我已将 cpp-netlib 从 v0.11.0 升级到 0.13.0 并遇到了一些困难。
以前,当向服务器发送请求时,可以从请求对象中读取请求的正文。
当我使用 v0.13.0 向服务器发送相同的请求时,请求正文现在为空。
请求对象的其余部分似乎是正确的——只有主体是空的。
我需要做些不同的事情吗?我在网站上找不到任何显示身体提取方式的示例。
我已经从 hello world 示例中确认了相同的行为。
#include <boost/network/protocol/http/server.hpp>
#include <iostream>
namespace http = boost::network::http;
struct hello_world;
typedef http::server<hello_world> server;
struct hello_world
{
void operator()(const server::request &request, server::connection_ptr connection)
{
///////////////////////////////////
// request.body is empty
///////////////////////////////////
server::string_type ip = source(request);
unsigned int port = request.source_port;
std::ostringstream data;
data << "Hello, " << ip << ':' << port << '!';
connection->set_status(server::connection::ok);
connection->write(data.str());
}
};
int main(int argc, char *argv[]) {
try {
hello_world handler;
server::options options(handler);
server server_(options.address("192.168.0.19").port("9999"));
server_.run();
}
catch (std::exception &e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}
这是我发送的请求:
Curl -v -X POST http://192.168.0.19:9999/my-app/rest/foo/1.0/bar -H 'Content-Type: application/x-www-form-urlencoded' --data key=value