locked
Force To Read HttpWebResponse.GetResponseStream() When Content-Length Is Zero RRS feed

  • Question

  • As title said.

    Sometime an HTTP response from remote server includes Content-Length header with zero value, but it still return HTTP body.  The body can still be obtained with jQuery in browser, but using HttpWebResponse.GetResponseStream() can't read anything. How do I force to read it? Thanks everyone.

    Here's an example of HTTP response which I met.

    HTTP/1.1 200 OK
    Connection: keep-alive
    Cache-Control: no-cache,no-store
    Content-Type: text/plain 
    Content-Length: 0
    Date: Mon, 30 Sep 2013 09:34:21 GMT

    <Body>



    • Edited by Vendenberg Monday, September 30, 2013 10:19 AM
    Monday, September 30, 2013 10:16 AM

Answers

  • Hi Vendenberg,

    By reviewing the definition of the HttpWebResponse class, I think we could not force to read it. In order to get around this issue, I recommend you add try-catch block into your code. When you catch the exception, you could do what you want.

    Best Regards,

    Hetro


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, October 3, 2013 9:41 AM

All replies

  • Can you please post the code so we can see how you are creating your web request?

    I assume that that you are setting request "Accept" property/header or something similar which causes zero return value.


    Josip Habjan      http://habjan.blogspot.com

    Monday, September 30, 2013 11:09 AM
  • Hi Vendenberg,

    By reviewing the definition of the HttpWebResponse class, I think we could not force to read it. In order to get around this issue, I recommend you add try-catch block into your code. When you catch the exception, you could do what you want.

    Best Regards,

    Hetro


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, October 3, 2013 9:41 AM