Problem reading stream from httpclient RRS feed

  • Question

  • Hello,

    I am getting problem reading stream in below code.

    Function A:

    Stream responseStream = await HttpHandler.DoPostRequestDownload(); if (responseStream != null) { while(stream.ReadByte()>0) // Getting exception here { // My Logic

    } }

    DoPostRequestDownload Method Which Return Task<Stream>

    HttpResponseMessage aResponse = await httpClient.SendAsync(httprequestMessage, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false); aResponse.EnsureSuccessStatusCode(); Stream stream = await aResponse.Content.ReadAsStreamAsync();

    //while(stream.ReadByte()>0) // It works here
         // My Logic
    // } return stream;

    Please can you help to know what I am doing wrong?

    Thanks in advance.

    • Edited by zee_patel Tuesday, August 12, 2014 2:00 PM
    Tuesday, August 12, 2014 2:00 PM


All replies

  • What's the problem you're facing?

    Hope it helps!

    Tuesday, August 12, 2014 4:59 PM
  • Hi Kualsangar,

    Thanks for Reply,

    As I mentioned in my code block that reading stream in DoPostRequestDownload is working fine, but if I send that stream to my Function "A" than I am getting exception while reading stream in that function.

    Wednesday, August 13, 2014 5:12 AM
  • Okay, got the solution.

    Actually my httpclient was in Using block, so returning response from that block was disposing my object.

    Thanks for reply.

    Wednesday, August 13, 2014 6:23 AM