[英]Boost Asio receive unknown Number?
I wrote a Http/Rest Client. 我写了一个Http / Rest客户端。
The Main Problem is that i recieve some unkown digits within the requested data. 主要问题是我在请求的数据中收到了一些未知数字。 I really don´t know where they come from..
我真的不知道它们来自哪里。
e0b
<html>
<head>
[...]
</body>
</html>
0
You see the e0b and the 0 at the end. 您会看到e0b和结尾处的0 。 In big xml files for example i got something like this:
例如在大的xml文件中,我得到的是这样的:
<sometag id="somei
2000
d"><child>
...
</child></some
2000
tag>
It is irreproducible by me. 这是我无法复制的。
My Code: 我的代码:
// read the response status code
boost::asio::streambuf httpStreamBufferResponse;
boost::asio::read_until(httpSocket, httpStreamBufferResponse, "\r\n");
// check status code and validate
istream httpResponseIStream(&httpStreamBufferResponse);
// temp var for version
string sHttpVersion;
httpResponseIStream >> sHttpVersion;
// temp var for status code
unsigned int uiStatusCode;
httpResponseIStream >> uiStatusCode;
// fetch status message and switch it
string sStatusMessage;
getline(httpResponseIStream, sStatusMessage);
if(!httpResponseIStream || sHttpVersion.substr(0, 5) != "HTTP/"){
new Note(eNotesType(ERROR), "Request Interrupt", "Invalid Request Response");
Log::write("ERROR: Request Interrupt: Invalid Request Response");
}
// != 200 even means that something is not OK
if(uiStatusCode != 200){
this -> sHttpStatusCode = uiStatusCode;
new Note(eNotesType(WARNING), "Request Response "
+ boost::lexical_cast<string>(uiStatusCode), httpErrorToString.at(uiStatusCode));
Log::write("WARNING: Request Response "
+ boost::lexical_cast<string>(uiStatusCode) + ": " + httpErrorToString.at(uiStatusCode));
}
// Read the response headers, which are terminated by a blank line.
boost::asio::read_until(httpSocket, httpStreamBufferResponse, "\r\n\r\n");
// Process the response header
stringstream responseSStream;
string responseSHeader;
while (getline( httpResponseIStream, responseSHeader ) && responseSHeader != "\r" ) {
responseSStream << responseSHeader;
}
// store header in member variable
this -> sHttpResponseHeader = sHttpVersion + " " + boost::lexical_cast<string>(uiStatusCode) + " "
+ httpErrorToString.at(uiStatusCode) + "\n" + responseSStream.str();
// read until EOF and writing data to output as we go.
ostringstream responseOSStream;
while(boost::asio::read(httpSocket, httpStreamBufferResponse, boost::asio::transfer_at_least(1), error)){
responseOSStream << &httpStreamBufferResponse;
}
// store content in member variable
this -> sHttpResponseContent = responseOSStream.str();
// if there is no EOF
if(error != boost::asio::error::eof){
new Note(eNotesType(ERROR), "Request Interrupt", "Invalid Response End");
Log::write("ERROR: Request Interrupt: Invalid Response End");
}
// catch not known exceptions properly
} catch (exception& e){
string exceptionMessage = e.what();
new Note(eNotesType(ERROR), "Exception", exceptionMessage);
Log::write("ERROR: Exception: " + exceptionMessage);
}
// log http standby
Log::write("http status: standby");
It would be a great pleasure if anybody got ANY idea where this come from..?! 这将是一个非常高兴,如果有人有任何想法,这来自..?!
My nerves are on edge.. 我紧张不安。
Your code is claiming HTTP/1.1 compliance and doesn't actually comply with HTTP/1.1's requirements. 您的代码声称符合HTTP / 1.1,实际上不符合HTTP / 1.1的要求。 Either don't claim HTTP/1.1 compliance or make sure your code does everything the standard says a client must do.
不要声称符合HTTP / 1.1,或者不要确保您的代码可以执行标准要求客户端执行的所有操作。
All HTTP/1.1 applications MUST be able to receive and decode the "chunked" transfer-coding, and MUST ignore chunk-extension extensions they do not understand.
所有HTTP / 1.1应用程序必须能够接收和解码“分块”传输编码,并且必须忽略它们不理解的块扩展名。 -- HTTP/1.1 specification, section 3.6.1
-HTTP / 1.1规范,第3.6.1节
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.