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

Created 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


Viewing all articles
Browse latest Browse all 4845

Trending Articles



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