Forum Moderators: open

Message Too Old, No Replies

HttpWebRequest and POST button click

         

k2k2e6

5:45 pm on Jan 3, 2003 (gmt 0)

10+ Year Member



Hi, I am trying to write an application which will POST to a URL by sending values for text box controls and the submit button. For some reason, the ASP.NET does not think that I have sent enough info for a button click. What could I be doing wrong?

I captured the HTTP packet when doing the POST manually and I used the same contents (other than viewstate) in POST.

Thanks
Pawan

Console.WriteLine("Got a login page")

Dim strPost As String = "textboxUserid=a&textboxPassword=b&buttonLogin=Log+in"
Dim myWriter As StreamWriter
Dim objRequest As HttpWebRequest = CType(WebRequest.Create(myResponse.ResponseUri), HttpWebRequest)
objRequest.Method = "POST"
objRequest.ContentLength = strPost.Length
objRequest.ContentType = "application/x-www-form-urlencoded"
Try
myWriter = New StreamWriter(objRequest.GetRequestStream())
myWriter.Write(strPost)
Catch e As Exception
Console.WriteLine(e.ToString)
Finally
myWriter.Close()
End Try

Dim objResponse As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse)
Dim newsr As New StreamReader(objResponse.GetResponseStream())
Dim respText As String = newsr.ReadToEnd()
newsr.Close()
Console.WriteLine(respText)

duckhunter

5:16 am on Jan 5, 2003 (gmt 0)

10+ Year Member



The button on the page you are posting to; is it a ASP.NET form (runat=server) or is the page looking at Page.IsPostBack?

This would require you actually click the button on the page rather than posting in the value.