Hi all,
I have a VB.Net code that basically requests a page using HttpWebRequest and returns the response that I print out in a text box on a form.
My next step is to POST to that page.
This page was developed in ASP 3.0 and is very simple.
It contains two input fields and a button that takes the values of those two fields and writes them out on the same page. Nothing fancy... plain and boring, only for testing purposes.
Using my VB.Net application, I'm trying to access that page and POSTing the values of those two input fields and then returning the response back.
Every time it fails and it returns an exception with the following message: "The remote server returned an error: (405) Method Not Allowed."
Below is the code I'm using to do this:
I'm not sure what I'm doing wrong.
Could it be that the web server I'm hitting is missing some library?
Or is HttpWebRequest not compatible with old ASP3.0?
Any input is greatly appreciated.
Thank you all for your time and help with this.
- Pascal
I have a VB.Net code that basically requests a page using HttpWebRequest and returns the response that I print out in a text box on a form.
My next step is to POST to that page.
This page was developed in ASP 3.0 and is very simple.
It contains two input fields and a button that takes the values of those two fields and writes them out on the same page. Nothing fancy... plain and boring, only for testing purposes.
Using my VB.Net application, I'm trying to access that page and POSTing the values of those two input fields and then returning the response back.
Every time it fails and it returns an exception with the following message: "The remote server returned an error: (405) Method Not Allowed."
Below is the code I'm using to do this:
Code:
Dim objWebReqt As HttpWebRequest
Dim objWebResp As HttpWebResponse
Dim POSTStr As String
Dim sr As StreamReader
Dim sw As StreamWritter
objWebReqt = objWebReqt.Create("http://www.somesite.com")
POSTStr = "firstName=" & HttpUtility.UrlEncode("John") & _
"&lastName=" & HttpUtility.UrlEncode("Doe")
objWebReqt.Method = "POST"
objWebReqt.ContentLength = POSTStr.Length
sw = New StreamWritter(objWebReqt.GetRequestStream())
sw.Write(POSTStr)
sw.Close()
objWebResp = objWebReqt.GetResponse()
sr = New StreamReader(objWebResp.GetResponseStream())
txtResult.Text = sr.ReadToEnd()
Could it be that the web server I'm hitting is missing some library?
Or is HttpWebRequest not compatible with old ASP3.0?
Any input is greatly appreciated.
Thank you all for your time and help with this.
- Pascal