2

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?

Redwood
  • 66,744
  • 41
  • 126
  • 187
  • can you ping the url from the commandline? – µBio Jun 11 '10 at 21:09
  • Yes, although here's an interesting thing: if I hit the URL in Firefox it prompts me to download the file as expected, but even though Firefox Downloads window says the file is around 1.8 KB when opened the file is empty (it also still has the extension .part). So I may start looking further afield for my problem. – Redwood Jun 11 '10 at 21:26
  • Dump the response header fields before you read the entity body. If the content length is being advertised > 0, but there is nothing in the stream itself, you can see this happen. – feroze Jun 13 '10 at 22:04

0 Answers0