Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Alan Warren
Alan Warren
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

Fantastic! Really appreciate the help.