title: How to read a response with Content-Length 0?
body: <p>I need to read a body of a response where a <code>Content-Length</code> is explicitly specified as zero. But the <code>stream.Read</code> does not read anything and returns <code>0</code>. When the <code>Content-Length</code> header is not present, it reads all the bytes successfully.</p>
  
  <p>When I open the web page in the browser it is empty, but I can see the contents in Fiddler.</p>
  
  <p>Is there any way to get the <code>Stream</code> returned from <a href="https://docs.microsoft.com/en-us/dotnet/api/system.net.httpwebresponse.getresponsestream?view=netframework-4.8" rel="nofollow noreferrer"><code>GetResponseStream</code></a> to read the bytes when the <code>Content-Length</code> is 0?</p>
  
  <p>Sample response:</p>
  
  <pre><code>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 -
  </code></pre>
  
  <p>Simplified version of the code:</p>
  
  <pre><code>using(var stream = httpRes.GetResponseStream())
  {
       while (true)
       {
            var bytesRead = stream.Read(
                              responseBuffer,
                              0,
                              responseBuffer.Length);
  
            // other stuff
       }
  }
  </code></pre>