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
(HTTP Body)
Looking through the source code I could not find a way to force this behavior. Probably there's nothing you can do.
Try disabling HTTP pipelining. Maybe HttpWebRequest does not rely on the content length in that case. It is unlikely that it will help.
Either use a different HTTP library, or send the request using TcpClient
. You can use Fiddler to copy a template HTTP request and use that as the basis for yours. Should not be a lot of work.
You could also create a rewriting proxy that removes the header. That's probably a high-effort solution.
First question - Where did you get the HTTP response? Did you capture it with Fiddler or are you typing in what you think you're seeing by examining the HttpWebResponse in a debugger? I would suggest running this with Fiddler and examining the complete response headers if you didn't already.
We need to establish first if the Content-Length is being returned with a value of zero or if some of the other code in your project is causing you to interpret it as zero or to set your copy of the content length to zero.
I think one of two things is happening here:
Harold
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.