I need to read a body of a response where a Content-Length
is explicitly specified as zero. But the stream.Read
does not read anything and returns 0
. When the Content-Length
header is not present, it reads all the bytes successfully.
When I open the web page in the browser it is empty, but I can see the contents in Fiddler.
Is there any way to get the Stream
returned from GetResponseStream
to read the bytes when the Content-Length
is 0?
Sample response:
HTTP/1.1 200 OK
Cache-Control: public, must-revalidate
ETag: "c7f40cb26b1e95c2245f1584371465582f996a8a88b34a2cc99bbe922b1a2857"
Vary: Accept-Encoding
X-Request-Id: 4b799b6d-cd68-47f7-a392-4fd0a327f5de
X-Runtime: 0.001646
Content-Length: 0
- some content -
Simplified version of the code:
using(var stream = httpRes.GetResponseStream())
{
while (true)
{
var bytesRead = stream.Read(
responseBuffer,
0,
responseBuffer.Length);
// other stuff
}
}