You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I test the http sync server example,but post request body is empty.
cpp-netlib version is cpp-netlib-0.12.0-final-104-gb284b14.
Here is my code:
#include <boost/network/protocol/http/server.hpp>
#include <iostream>
namespace http = boost::network::http;
/*<< Defines the server. >>*/
struct hello_world;
typedef http::server<hello_world> server;
/*<< Defines the request handler. It's a class that defines two
functions, `operator()` and `log()` >>*/
struct hello_world {
/*<< This is the function that handles the incoming request. >>*/
void operator()(server::request const &request, server::connection_ptr connection) {
server::string_type ip = source(request);
unsigned int port = request.source_port;
//const auto header = request.headers();
for(const auto& header : request.headers)
{
std::cout<<"header.name:"<< header.name<<"headr.value:"<<header.value<< std::endl;
}
> ////!!!! the body is empty!!!!
std::cout<<"body:"<< body(request)<< std::endl;
std::cout<<"request.uri():"<<std::string(destination(request))<< std::endl;
std::ostringstream data;
data << "Hello, " << ip << ':' << port << '!'<<" "<<bodystr;
connection->write(data.str());
}
};
int main(int argc, char *argv[]) {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " address port" << std::endl;
return 1;
}
try {
/*<< Creates the request handler. >>*/
hello_world handler;
/*<< Creates the server. >>*/
server::options options(handler);
server server_(options.address(argv[1]).port(argv[2]));
/*<< Runs the server. >>*/
server_.run();
}
catch (std::exception &e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}
So,why.
The text was updated successfully, but these errors were encountered:
choujayyl
changed the title
POST request body is empty,http sync server not async
POST request body is empty,http sync server not async (0.12.0 final)
Oct 17, 2018
We no longer have a "sync" HTTP server in 0.12.0 -- you need to pull the data from the connection pointer. In this case the body is always empty, but the connection is still open, and you can use the read function to pull the data out:
I test the http sync server example,but post request body is empty.
cpp-netlib version is cpp-netlib-0.12.0-final-104-gb284b14.
Here is my code:
So,why.
The text was updated successfully, but these errors were encountered: