Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

Commented Unassigned: bytes read from response body stream is less than "Content length" [51]

$
0
0
Hi Casablanca,

I am trying to read body stream from a http_response, occasionally I read out less data than reported by "content length". Here is my code:

size_t contentLen = response.headers().content_length();
rawptr_buffer<char> rbuf(buffer, bufSize);
size_t bytesRead = response.body().read_to_end(rbuf).get();

Most of the time, bytesRead == contenLen. sometimes: bytesRead < contentLen. I also tried following way:
size_t contentLen = response.headers().content_length();
response.content_ready.wait();
size_t bytesRead = response.body().streambuf().scopy(buffer, contentLen);

The issue remains. It seems bytesRead == http_msg::m_data_available.

My question is:
1. is it expected that bytesRead < contenLen?
2. What is the correct way to read out all contents?

Thanks in advance for your help.

Vincent

Comments: Hi Vincent, Taking a quick look I don't see any reason why you should be encountering less bytes in the response body stream than reported in the Content-Length header. read_to_end should work find to get the whole body as raw bytes. To help me out investigating this can you please provide the following information. 1. What platform and configuration are you running? 2. What OS are you running on? 3. Also it would be great if you could share with me a public server that I can request at that the issue reproduces for you one. If not could you share any information about the response data from the server, perhaps the output from http_response::to_string()? Thanks for reporting this issue. Steve

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>