Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Web Exception !

Web Exception !

Scheduled Pinned Locked Moved Visual Basic
comsysadminmcphelptutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AliAmjad
    wrote on last edited by
    #1

    I'm getting an unusual error message may be I'm wrong here is the error can anyone please tell me how to resolve it: The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF And here is the code that raised this error:

        Dim wr As HttpWebRequest
        Dim wrs As HttpWebResponse
    
        wr = HttpWebRequest.Create("http://www.google.com/")
        wr.Method = "HEAD"
        wrs = wr.GetResponse()
        MsgBox(wrs.Headers.ToString())
    

    AliAmjad(MCP) First make it Run THEN make it Run Fast!

    D 1 Reply Last reply
    0
    • A AliAmjad

      I'm getting an unusual error message may be I'm wrong here is the error can anyone please tell me how to resolve it: The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF And here is the code that raised this error:

          Dim wr As HttpWebRequest
          Dim wrs As HttpWebResponse
      
          wr = HttpWebRequest.Create("http://www.google.com/")
          wr.Method = "HEAD"
          wrs = wr.GetResponse()
          MsgBox(wrs.Headers.ToString())
      

      AliAmjad(MCP) First make it Run THEN make it Run Fast!

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      According to the error message, your code didn't generate the error, Google's web server did. HttpWebRequest is correct is saying so because it's following the parsing rules for HTTP 1.1 headers closer to the RFC specification than Google web server did putting the headers together. It's not Google's fault really, but the people who wrote the web server. There's an old recommendation in the RTF for HTTP 1.0 that said something like: "the line terminator for message-header fields is the sequence CRLF. However, we recommend that applications, when parsing such headers, recognize a single LF as a line terminator and ignore the leading CR." The headers comming back from the server ARE, according to which section of the RFC for HTTP you're reading, malformed. You can turn on an option in your applications app.config file to force HttpWebRequest to relax it's parsing rules and suddenly start working with a large collection of web servers that were never "fixed" because "they worked before!"

      <configuration>
      <system.net>
      <settings>
      <httpWebRequest useUnsafeHeaderParsing="true" />
      </settings>
      </system.net>
      </configuration>

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      A 1 Reply Last reply
      0
      • D Dave Kreskowiak

        According to the error message, your code didn't generate the error, Google's web server did. HttpWebRequest is correct is saying so because it's following the parsing rules for HTTP 1.1 headers closer to the RFC specification than Google web server did putting the headers together. It's not Google's fault really, but the people who wrote the web server. There's an old recommendation in the RTF for HTTP 1.0 that said something like: "the line terminator for message-header fields is the sequence CRLF. However, we recommend that applications, when parsing such headers, recognize a single LF as a line terminator and ignore the leading CR." The headers comming back from the server ARE, according to which section of the RFC for HTTP you're reading, malformed. You can turn on an option in your applications app.config file to force HttpWebRequest to relax it's parsing rules and suddenly start working with a large collection of web servers that were never "fixed" because "they worked before!"

        <configuration>
        <system.net>
        <settings>
        <httpWebRequest useUnsafeHeaderParsing="true" />
        </settings>
        </system.net>
        </configuration>

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        A Offline
        A Offline
        AliAmjad
        wrote on last edited by
        #3

        I've done some research before posting this question on Code Project and found the same solution in Msdn forum and did the same thing but it didn't display the headers received from the server but now it did I think there was something wrong with my network connection. As far as solution goes don't you think that Microsoft should make this class more fault tolerant so that it can handle such situations.

        AliAmjad(MCP) First make it Run THEN make it Run Fast!

        D 1 Reply Last reply
        0
        • A AliAmjad

          I've done some research before posting this question on Code Project and found the same solution in Msdn forum and did the same thing but it didn't display the headers received from the server but now it did I think there was something wrong with my network connection. As far as solution goes don't you think that Microsoft should make this class more fault tolerant so that it can handle such situations.

          AliAmjad(MCP) First make it Run THEN make it Run Fast!

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          AliAmjad wrote:

          As far as solution goes don't you think that Microsoft should make this class more fault tolerant so that it can handle such situations.

          They did!! As I've already said, you have to turn this option on in order to use the non-RFC compliant parser. In this particular case, the guy who the HttpWebRequest class wasn't as lazy as the guy who wrote the web server that Google, and tons of other sites, are using.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups