locked
WebException Protocol, Need Expert Help RRS feed

  • Question

  • Hey

    Okay basically my application is accessing many web pages and grabbing the source code to parse, due to the nature of this, I use try catch exception block, upon finishing, I noticed that the follow error is caught many times:

    Code:
    "System.Net.WebException: The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF\r\n   at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)\r\n   at System.Net.WebClient.DownloadString(Ur...
    Now naturally I've done some research into this via mostly Googling

    "The server committed a protocol violation."

    Now I've found that you can apparently set a useUnsafeHeaderParsing apparently found in the WebRequest class, but for some reason I just can't see it:

    http://img33.imageshack.us/img33/5465/progps.jpg

    also I think this can be altered in a ASP.NET app via using the web.config file, but obviously I don't have one :P.

    I'd really appreciate some advice on this from the experts.
    Saturday, August 8, 2009 9:58 PM

Answers

  • Hi,
    useUnsafeHeaderParsing is not a member of the WebRequest class (AFAIK there are no camel case properties or methods in the whole BCL), but a setting you have to place in your config files.
    There are workarounds to set it programmatically but that more or less still amounts fiddling with the config files.
    The issue was reported some time ago on connect, and you may want to look at the response.

    A rather drastic alternative is to use a WebBrowser control to download the page and then inspecting either its DOM (Document) or directly the HTML text (DocumentText). The control uses the same engine that IE uses and is therefore less picky about the protocol.
    I'm mentioning this for completeness: the WebBrowser control is very demanding in terms of resources, and may therefore not be suitable for the task you describe in your other post (which I guess is related).

    HTH
    --mc
    • Proposed as answer by Lex LiMVP Monday, August 10, 2009 2:59 AM
    • Marked as answer by Harry Zhu Friday, August 14, 2009 7:46 AM
    Sunday, August 9, 2009 2:34 AM