【发布时间】:2015-06-05 17:13:29
【问题描述】:
我正在尝试通过 boost asio 向服务器发送 HTTP 请求。我有以下在 c++ 中创建的请求:
static const std::string TEMPLATE_HEADER =
"POST " + HTTP_PATH + " HTTP/1.1\r\n"
"Content-Type: application/json\r\n"
"Host: " + HOST_TAG + "\r\n"
"{ " + TEMPLATE_BODY + " }\r\n\r\n";
我发送的实际请求是这样的:
POST /eikon/authsession/machines/ HTTP/1.1 Content-Type: application/json Host: amers1.am.cp.icp2.mpp.ime.reuters.com:80 { "machineID" : "EP-03A482F1B88A","password" : "PasswordReset","takeESOControl" : "false","deviceID" : "123" }
这在使用 Postman(Google Chrome 扩展程序)时有效,但在使用 boost asio 时似乎不起作用。我执行以下操作(上面的 HTTP 请求是 strTemp。
// Write the request to the buffer
size_t request_length = strTemp.length();
boost::asio::write(s, boost::asio::buffer(strTemp, request_length));
char reply[max_length];
// When a reply is received ending in the correct tag we are looking for, store it in the response buffer
boost::asio::streambuf response;
boost::asio::read_until(s, response, Constants::BRACE_TAG);
BRACE_TAG 变量 = "}"(因为返回的响应以大括号结尾。
我收到一个异常返回,上面写着“异常:read_until:文件结束”。
有人知道发生了什么吗?
谢谢。
【问题讨论】:
-
这个问题和你的问题posted 6 hours ago一模一样。转发您的问题以引起注意是不礼貌的行为。
-
我在 6 小时内没有得到任何答案,但现在发布它我得到了答案。无论如何,它都被删除了——如果我把它留下并再次发布,那将是一种不礼貌的行为。
-
请注意,是 我 回答的。我什至赞成。我不知道你为什么这么生气。哦,我在回答你问题的“旧”版本,但后来你删除了它。
标签: c++ http boost boost-asio