Q:

Unable to read HttpResponse from HTTPS

public void HttpsRequest(string address)
    {
        string data;
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
        request.Method = "GET";

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        byte[] resp = new byte[(int)response.ContentLength];
        Stream receiveStream = response.GetResponseStream();
        using (StreamReader reader = new StreamReader(receiveStream, Encoding.ASCII))
        {
            data = reader.ReadToEnd();
        }
    }

I get an Arithmetic operation resulted in an overflow when I am trying to read a page over https. Errors occur because the response gives me ContentLenght = -1.
Using fiddler I can see that the page was received. Some other websites using HTTPS works fine but most of them not.

A:

If I query https://www.google.com, I get the same error message, because not every response has a content length. Use this code to avoid the problem: 
public static void HttpsRequest(string address)
{
  string data;
   HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
   request.Method = "GET";

   using (WebResponse response = request.GetResponse())
  {
    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    {
        data = reader.ReadToEnd();
    }
  }
}

