提升asio read_u直到文件的异常结束
Boost asio read_until exception end of file?
我正试图通过boost asio向服务器发送HTTP请求。我在c++中创建了以下请求:
static const std::string TEMPLATE_HEADER =
"POST " + HTTP_PATH + " HTTP/1.1rn"
"Content-Type: application/jsonrn"
"Host: " + HOST_TAG + "rn"
"{ " + TEMPLATE_BODY + " }rnrn";
我发送的实际请求是:
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(一个谷歌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变量="}"(返回的响应以大括号结尾。
我收到一个异常,上面写着"exception:read_until:End of file"。
有人知道发生了什么事吗?
谢谢。
-
在标题和正文之间应该有一条双换行符:
"Host: " + HOST_TAG + "rnrn"
-
您可能需要发送Content-Length标头(HTTP标头中的"Content-Length"字段是什么?)。邮差可能会为你添加
相关文章:
- 加载与引用 .NET DLL 位于同一文件夹中的引用的 .NET DLL 时"Not found"异常
- 读取文件时引发异常
- 尝试将数字写入二进制文件时引发异常
- 为什么我尝试在 OpenGL 中加载的 3ds 文件会出现此未经处理的异常?
- 如何构建一个异常类来报告C++中的哪些文件和行号?
- 从二进制文件中读取元素时引发异常(引发异常:读取访问冲突. _Pnext 0xB414D4)
- 读取 MAC 地址时文件读取异常
- free():在有效指针异常中-使用流读取巨大文件时
- 尝试将 std::cerr 重定向到文件时出现访问冲突异常
- 文件流析构函数是否可以在C++中引发异常?
- 挂钩创建文件抛出异常:读取访问冲突
- 仅捕获异常就可以检测所有二进制文件在C 中读取错误是否足够
- 如果文件为c ,如何抛出异常
- 尝试使用 wxWidgets 从 zip 打开不存在的文件时无法捕获的异常
- 加载C DLL文件时,如何修复异常_access_violation
- C++ 读取文件和写入变量时未处理的异常 - getline 错误?
- G++ 和 CL(VS2017) 都编译成功,但 cl 编译的可执行文件运行异常
- 格式化文件异常被 try catch 块忽略
- 如何在 bash 文件异常退出时捕获异常
- 文件异常和光标移动c++