簡體   English   中英

Boost asio read_until 異常文件結束?

[英]Boost asio read_until exception end of file?

我正在嘗試通過 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:文件結束”。

任何人都知道發生了什么?

謝謝。

  1. 標題和正文之間應該有一個雙換行符:

     "Host: " + HOST_TAG + "\\r\\n\\r\\n"
  2. 您可能需要發送 Content-Length 標頭( HTTP 標頭中的“Content-Length”字段是什么? )。 郵遞員可能會為您添加

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM