title: Truncated response received using HttpWebRequest
body: <p>I'm using the following code to make HttpWebRequests to a web site:</p>
  
  <pre><code>public static HttpWebResponse SendGETRequest(string url, string agent, CookieContainer cookieContainer)
  {
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
     request.UserAgent = agent;
     request.Method = "GET";
     request.ContentType = "text/html";
     request.CookieContainer = cookieContainer;
  
     return (HttpWebResponse)request.GetResponse();
  }
  </code></pre>
  
  <p>Everything worked fine with several web pages until I tried with a new one and only received the last part of the page. This is the received response:</p>
  
  <pre><code>&lt;tr&gt; 
      &lt;td colspan="2" height="5"&gt;&lt;spacer type="block" width="100%" height="5"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The header is correct and says that only the received data is sent. The following are the headers of the request and response:</p>
  
  <p>Request:</p>
  
  <pre><code>GET /Broker/Ops/FichaContratoJS.asp?nc=815044&amp;IP=5&amp;YY=2012&amp;M=6&amp;St=0&amp;CC=FESX201206 HTTP/1.1  
  User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19  
  Content-Type: text/html  
  Host: www.xxxx.com  
  Cookie: ASPSESSIONIDACBDCDBT=MGDNMNABOANDMILHBNCIDFCH;Autenticacion=Sid=230fae3d%2De0e2%2D4df1%2D8aa8%2D000fb352eaef&amp;IdUsuarioWeb=xxxx; ASPSESSIONIDACBCCDAT=AFDJMNABAFJDDHABLOLAINDK; ASPSESSIONIDCADCBCAT=CEBJGNABLCALPJLDJFPBMLDE
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>HTTP/1.1 200 OK  
  Date: Wed, 09 May 2012 07:25:03 GMT  
  Server: Microsoft-IIS/6.0  
  X-Powered-By: ASP.NET  
  Pragma: no-cache  
  **Content-Length: 155**  
  Content-Type: text/html  
  Expires: Wed, 09 May 2012 07:24:02 GMT  
  Set-Cookie: Autenticacion=Sid=230fae3d%2De0e2%2D4df1%2D8aa8%2D000fb352eaef&amp;IdUsuarioWeb=xxxx; path=/  
  Cache-control: no-cache  
  </code></pre>
  
  <p>Doing the same with a web browser works fine and returns a content length of about 4000 bytes.</p>
  
  <p>Any ideas?</p>
  
  <p>PD: Just in case it matters I'm doing several calls to the SendGETRequest from different threads to the same site but as there are no shared variables I think it shouldn't make a difference.</p>
  
  <p>EDIT: This is the extension I use to extract the text from the Stream:</p>
  
  <pre><code>    public static string ReadTextResponse(this Stream stream)
      {
          int count;
          Encoding enconding = System.Text.Encoding.GetEncoding(1252);
          System.Text.StringBuilder stringBuilder = new StringBuilder();
          byte[] buffer = new byte[1023];
  
          do
          {
              count = stream.Read(buffer, 0, buffer.Length);
  
              if (count != 0)
              {
                  string tempString = enconding.GetString(buffer, 0, count);
                  stringBuilder.Append(tempString);
              }
          }
          while (count &gt; 0);
  
          return stringBuilder.ToString();
      }
  </code></pre>
  
  <p>As far as I know it's correct. Also, <strong>note that the response header from the server contains the length of the truncated data</strong></p>