提升asio https发布请求正文

时间:2019-05-29 22:51:42

标签: c++ http http-headers boost-asio

我正在使用boost asio库通过tcp套接字发送发布请求。在服务器端已收到请求,但没有参数,这是怎么回事?

boost::asio::streambuf request_;
std::string postfields ("username=user1&password=any");
std::ostream request_stream(&request_);
request_stream << "POST " << /somepath << " HTTP/1.1\r\n";
request_stream << "Host: " << somehost.com << "\r\n";
request_stream << "User-Agent: C/1.0" << "\r\n";
request_stream << "Content-Type: application/x-www-form-urlencoded \r\n";
request_stream << "Accept: application/json\r\n";
request_stream << "Content-Length: " << postfields.length() << "\r\n"
request_stream << "Connection: close\r\n\r\n";
request_stream << postfields;
request_stream << "\n\n"; // tried with and without this line

boost::asio::async_write(socket_, request_,
                      boost::bind(&client::handle_write_request, shared_from_this(),
                              boost::asio::placeholders::error));

当我打印请求时,它看起来像这样

POST /somepath HTTP/1.1
Host: somehost.com
User-Agent: C/1.0
Content-Type: application/x-www-form-urlencoded
Accept: application/json
Connection: close

username=user1&password=any

在服务器端,主体为空,没有参数。这有什么问题吗?

请不要将此标记为重复,因为我已经用尽了所有与此类似的stackoverflow问题。谢谢

0 个答案:

没有答案