I’m making a request to a website via the HttpWebRequest/HttpWebResponse objects.
I’m making several successful calls to the web site and every other call to the same dynamic page is failing.
In the debugger I’m getting a “Internal server error 500” fiddler also shows a 500 response and contains:
[Fiddler] Response Header parsing failed.
This can be caused by an illegal HTTP response earlier on this reused server socket-- for instance, a HTTP/304 response which illegally contains a body.
Response Data:
<plaintext>
0D 0A 3C 21 44 4F 43 54 59 50 45 20 48 54 4D 4C 20 50 55 42 4C 49 43 20 ..<!DOCTYPE HTML PUBLIC
22 2D 2F 2F 57 33 43 2F 2F 44 54 44 20 48 54 4D 4C 20 34 2E 30 20 54 72 "-//W3C//DTD HTML 4.0 Tr
61 6E 73 69 74 69 6F 6E 61 6C 2F 2F 45 4E 22 3E 0D 0A 3C 48 54 4D 4C 3E ansitional//EN">..<HTML>
0D 0A 09 3C 48 45 41 44 3E 0D 0A 09 09 3C 74 69 74 6C 65 3E 56 69 65 77 ...<HEAD>....<title>View
I’ve removed all the hex and viewed the page and is what I expect to be returned but for some reason the server is reporting a 500 and the HttpWebRequest object throws an exception on this.
I’ve tried all the other “fixes” for this issue and none work. It might just be malformed data sent from the server but is there a lower level object to use than HttpWebRequest that’s not a pita to work with?
EDIT: I didn’t include the entire hex/entire html block in the above example.
EDIT: Turning off fiddler I get this in the debugger
EDIT: So, from what I’ve seen the HttpWebResponse object is acting accordingly. The server is just flaky and sometime returns the same exact data with different http status codes. For a quick fix I just wrapped each call in a try/catch and in the catch block just retying the exact same call. So far it works great and semi-proves that it’s the sites fault and not the HttpWebResponse object.
The server committed a protocol violation. Section=ResponseStatusLine
Hei Jon,
Is the same outcome without Fiddler? (just printing the exception on screen). I had trouble sometimes with debuggers misbehavior.
If the server is returning intermittent error and you do not have control over it, I am afraid you can not do much. The message seems clear that is a standard for 304 that the response should not have a body, but the server can do whatever it wants, so it is pretty much its problem to address to.
See W3C: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
Regarding the HttpWebRequest, I never had any problems, and never heard of any cases it can not handle HTTP communication. But if the case is that you want to go nuts and handle the packets yourself, Google how to build your own HttpWebRequest with sockets.
This project could be a start:
http://www.codeproject.com/Articles/13486/A-Simple-Crawler-Using-C-Sockets