IOException reading from HttpWebResponse response stream over SSL

Posted by Lawrence Johnston on Stack Overflow See other posts from Stack Overflow or by Lawrence Johnston
Published on 2010-06-11T21:08:09Z Indexed on 2010/06/11 21:13 UTC
Read the original article Hit count: 998

Filed under:
|
|

I get the following exception when attempting to read the response from my HttpWebRequest:

System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream.
   at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.IO.StreamReader.ReadBuffer()
   at System.IO.StreamReader.ReadToEnd()
   ...

My code functions without issue when using http.

I am talking to a third-party device; I do not have access to the server code.

My code is as follows:

private string MakeRequest() {
   // Disable SSL certificate verification per
   // http://www.thejoyofcode.com/WCF_Could_not_establish_trust_relationship_for_the_SSL_TLS_secure_channel_with_authority.aspx
   ServicePointManager.ServerCertificateValidationCallback =
        new RemoteCertificateValidationCallback(delegate { return true; });

    Uri uri = new Uri("https://mydevice/mypath");
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
    request.Method = WebRequestMethods.Http.Get;

    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
        using (Stream responseStream = response.GetResponseStream()) {
            using (StreamReader sr = new StreamReader(responseStream.)) {
                return sr.ReadToEnd();
            }
        }
    }
}

Does anybody have any thoughts about what might be causing it?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ssl