ASP.net VB.net html post error

Hi. I am getting an error marked at the line marked 'XXXXX
"The server committed a protocol violation. Section=Response.Status.Line"
I'm not sure what this means

    Private Shared Sub start_post()

        Try



            'Our postvars
            Dim buffer As Byte() = Encoding.ASCII.GetBytes("test=postvar&test2=another")
            'Initialization, we use localhost, change if applicable
            Dim WebReq As HttpWebRequest = DirectCast(WebRequest.Create("http://127.0.0.1/test.php"), HttpWebRequest)
            'Our method is post, otherwise the buffer (postvars) would be useless
            WebReq.Method = "POST"
            'We use form contentType, for the postvars.
            WebReq.ContentType = "application/x-www-form-urlencoded"
            'The length of the buffer (postvars) is used as contentlength.
            WebReq.ContentLength = buffer.Length
            'We open a stream for writing the postvars
            Dim PostData As Stream = WebReq.GetRequestStream()
            'Now we write, and afterwards, we close. Closing is always important!
            PostData.Write(buffer, 0, buffer.Length)
            PostData.Close()
            'Get the response handle, we have no true response yet!
            Dim WebResp As HttpWebResponse = DirectCast(WebReq.GetResponse(), HttpWebResponse) 'XXXX
            'Let's show some information about the response
            Console.WriteLine(WebResp.StatusCode)
            Console.WriteLine(WebResp.Server)

            'Now, we read the response (the string), and output it.
            Dim Answer As Stream = WebResp.GetResponseStream()
            Dim _Answer As New StreamReader(Answer)
            Console.WriteLine(_Answer.ReadToEnd())

            'Congratulations, you just requested your first POST page, you
            'can now start logging into most login forms, with your application
            'Or other examples.

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
 
Alan WarrenConnect With a Mentor Applications DeveloperCommented:
Hi murbro,
The following gets a response:
  ?WebResp.StatusCode
  OK {200}
  ?WebResp.Server
  "Apache-Coyote/1.1"

Open in new window

    Private Shared Sub start_post()

    Try

      'Our postvars
      Dim buffer As Byte() = Encoding.ASCII.GetBytes("test=postvar&test2=another")

      'Initialization, we use localhost, change if applicable
      Dim WebReq As System.Net.HttpWebRequest = CType(System.Net.WebRequest.Create("http://www.experts-exchange.com/"), System.Net.HttpWebRequest)

      'Our method is post, otherwise the buffer (postvars) would be useless
      WebReq.Method = "POST"

      'We use form contentType, for the postvars.
      WebReq.ContentType = "application/x-www-form-urlencoded"

      'The length of the buffer (postvars) is used as contentlength.
      WebReq.ContentLength = buffer.Length

      'We open a stream for writing the postvars
      Dim PostData As System.IO.Stream = WebReq.GetRequestStream()

      'Now we write, and afterwards, we close. Closing is always important!
      PostData.Write(buffer, 0, buffer.Length)
      PostData.Close()

      'Get the response handle, we have no true response yet!
      Dim WebResp As System.Net.HttpWebResponse = CType(WebReq.GetResponse(), System.Net.HttpWebResponse)

      'Let's show some information about the response
      Console.WriteLine(WebResp.StatusCode)
      Console.WriteLine(WebResp.Server)

      'Now, we read the response (the string), and output it.
      Dim Answer As System.IO.Stream = WebResp.GetResponseStream()
      Dim _Answer As New System.IO.StreamReader(Answer)
      Console.WriteLine(_Answer.ReadToEnd())

      'Congratulations, you just requested your first POST page, you
      'can now start logging into most login forms, with your application
      'Or other examples.

    Catch ex As Exception
      MsgBox(ex.Message)
    End Try
  End Sub

Open in new window

When I tried to get a response from my local router 192.168.1.1, the code hit the Try Catch and returned a 401 "Unauthorised"


Alan ";0)
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Fantastic! Really appreciate the help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.