Problem of "The server committed a protocol violation. Section=ResponseStatusLine" in VB2005.NET

  • 14 years ago
    Hello All,

    I am making VB.NET application program to read data from other equipment.
    The following is my code.(VB2005.NET)
    ---------------code --------------------------
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.
    EventArgs) Handles Button2.Click
           Dim instance As WebException = Nothing
           Dim value As WebResponse

           TextBox2.Text = ""

           Dim url As String = "http://" + TextBox1.Text

            Dim url As String = "http://192.168.3.21/index1.htm/X"
            Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url)
    , httpWebRequest)

            Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.
    GetResponse(), HttpWebResponse)
     
           Dim receiveStream As Stream = myHttpWebResponse.GetResponseStream()
           Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")

           Dim readStream As New StreamReader(receiveStream, encode)
           Dim read(4096) As [Char]
           Dim count As Integer = readStream.Read(read, 0, 4096)
           While count > 0
               Dim str As New [String](read, 0, count)
               count = readStream.Read(read, 0, 4096)
               TextBox2.Text = TextBox2.Text + str
           End While

           readStream.Close()
           myHttpWebResponse.Close()

       End Sub
    -------------End of code --------------------

    I put the following code in app.config to solve this problem as other people
    recommended.

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

    However,  I still have a problem in " myHttpWebRequest.GetResponse "
    => The server committed a protocol violation. Section=ResponseStatusLine

    If any person has a good advice, please let me know!

    Thank you in advance,

    Ed,

























































  • 14 years ago
    Hi,

    I try your code and it works fine maibe is the url you are using. I put for testing purpose in the url "www.yahoo.com" and it return the html.
            Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.yahoo.com"), HttpWebRequest)
            Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
    
            Dim receiveStream As Stream = myHttpWebResponse.GetResponseStream()
            Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
    
            Dim readStream As New StreamReader(receiveStream, encode)
            Dim read(4096) As [Char]
            Dim count As Integer = readStream.Read(read, 0, 4096)
            While count > 0
                Dim str As New [String](read, 0, count)
                count = readStream.Read(read, 0, 4096)
                TextBox1.Text = TextBox1.Text + str
            End While
    
            readStream.Close()
            myHttpWebResponse.Close()
    



  • 14 years ago

    Thank you for your comment, Lexian!

    My problem was in other system which I want to communicate. I have to put header before real data to send. For example, "HTTP/1.0 200 ".

    I solved my problem after tring many times. .NET program will have no problem with Lexian's code.

    Thank you again for everybody!

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.” - Donald Knuth