title: HttpWebResponse.GetResponseStream().Length throws exception even result is 200 OK status
body: <p>I am trying to connect the web url from ASP.Net application to java web application using HttpWebRequest object and getting the status 200 OK. But when i try reading the response content using GetResponseStream() i am getting an error <strong>'responseStream.Length' threw an exception of type 'System.NotSupportedException'</strong></p>
  
  <p>Here is the code</p>
  
  <pre><code>string uri="https://myapp.com/mainservlet/";
  
  System.Net.HttpWebRequest hwrequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
              hwrequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
              hwrequest.AllowAutoRedirect = true;
              hwrequest.UserAgent = "http_requester/0.1";
              hwrequest.Timeout = 60000;
              hwrequest.Method = "POST";
              if (hwrequest.Method == "POST")
              {
                  hwrequest.ContentType = "text/xml";
                  // Use UTF8Encoding instead of ASCIIEncoding for XML requests:
                  System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                  byte[] postByteArray = encoding.GetBytes(postData);
                  hwrequest.ContentLength = postByteArray.Length;
                   System.IO.Stream  poststream = hwrequest.GetRequestStream();
                  poststream.Write(postByteArray, 0, postByteArray.Length);
                  poststream.Close();
              }
  
              //Get the Response now.
              hwresponse = (System.Net.HttpWebResponse)hwrequest.GetResponse();
  
           //  System.Xml.Linq.XDocument doc;
              //hwresponse.Method = "GET";
              string str = hwresponse.CharacterSet;
              string str1 = hwresponse.ContentEncoding;
              if (hwresponse.StatusCode == System.Net.HttpStatusCode.OK)
              {
  
                  System.IO.Stream responseStream = hwresponse.GetResponseStream();
                 // Here i am getting that exception
  </code></pre>
  
  <p><strong>Note:</strong> When i try paste the same url in browser it says </p>
  
  <p><em>Error 404--Not Found 
  From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
  10.4.5 404 Not Found
  The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.
  If the server does not wish to make this information available to the client, the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address.</em></p>
  
  <p>Also it entered in 200 OK status and shows exception. Could some one help me how to resolve/ suggession? </p>