J
Jonathan Amend
I have noticed that a lot of people were having a similar problem to mine
which involves using the POST method with the
HttpWebRequest/WebRequest/WebClient classes (.NET 1.1). The classes will
send out one HTTP packet that says content of a certain length will follow
but the second packet is never sent, which usually results in a 400 error
from the server. I've tried my code on both HTTP 1.0 and 1.1 servers and
both gave the same result. Here is my example:
Try
Dim LogInURL As String = "http://s2.starkingdoms.com/scripts/main.cgi"
'Dim LogInURL As String =
"http://sklone.homeip.net/scripts/BrowserLogin.aspx"
Dim Account As String = "blah"
Dim Password As String = "blah"
Dim Request As Net.HttpWebRequest = Net.HttpWebRequest.Create(LogInURL)
Request.ContentType = "application/x-www-form-urlencoded"
Request.Method = "POST"
Request.ProtocolVersion = Net.HttpVersion.Version10
'Request.ProtocolVersion = Net.HttpVersion.Version11
Dim RequsetStream As IO.Stream = Request.GetRequestStream()
Dim ASCIIEncoding As New System.Text.ASCIIEncoding
Dim PostData As Byte() = ASCIIEncoding.GetBytes("Account=" & Account &
"Password=" & Password)
RequsetStream.Write(PostData, 0, PostData.Length)
RequsetStream.Close()
Dim Reader As New
IO.StreamReader(Request.GetResponse().GetResponseStream())
Dim ResultHTML As String = Reader.ReadToEnd()
Reader.Close()
MsgBox(ResultHTML)
Catch ex As Exception
MsgBox(ex.Message)
End Try
And here's what happens:
POST /scripts/main.cgi HTTP/1.0
Content-Length: 25
Connection: Keep-Alive
Host: s2.starkingdoms.com
Followed by the Bad Request (400) error.
which involves using the POST method with the
HttpWebRequest/WebRequest/WebClient classes (.NET 1.1). The classes will
send out one HTTP packet that says content of a certain length will follow
but the second packet is never sent, which usually results in a 400 error
from the server. I've tried my code on both HTTP 1.0 and 1.1 servers and
both gave the same result. Here is my example:
Try
Dim LogInURL As String = "http://s2.starkingdoms.com/scripts/main.cgi"
'Dim LogInURL As String =
"http://sklone.homeip.net/scripts/BrowserLogin.aspx"
Dim Account As String = "blah"
Dim Password As String = "blah"
Dim Request As Net.HttpWebRequest = Net.HttpWebRequest.Create(LogInURL)
Request.ContentType = "application/x-www-form-urlencoded"
Request.Method = "POST"
Request.ProtocolVersion = Net.HttpVersion.Version10
'Request.ProtocolVersion = Net.HttpVersion.Version11
Dim RequsetStream As IO.Stream = Request.GetRequestStream()
Dim ASCIIEncoding As New System.Text.ASCIIEncoding
Dim PostData As Byte() = ASCIIEncoding.GetBytes("Account=" & Account &
"Password=" & Password)
RequsetStream.Write(PostData, 0, PostData.Length)
RequsetStream.Close()
Dim Reader As New
IO.StreamReader(Request.GetResponse().GetResponseStream())
Dim ResultHTML As String = Reader.ReadToEnd()
Reader.Close()
MsgBox(ResultHTML)
Catch ex As Exception
MsgBox(ex.Message)
End Try
And here's what happens:
POST /scripts/main.cgi HTTP/1.0
Content-Length: 25
Connection: Keep-Alive
Host: s2.starkingdoms.com
Followed by the Bad Request (400) error.