G
Guest
Hi
I have been trying to post data to a form on a web page using methods within the system.net namespace. I have followed all the documentation to the letter, but I just can't seem to post the form. The form has an event written in c# called Button1_Click. It seems that this event is not firing when the data is posted to the web form. The button is added to the page using <asp:Button id="Button1" runat="server" Text="Button1" OnClick="Button1_Click" /> The code used to submit the form is as follows
//encode the form data string into a byte arra
byte[] buffer = Encoding.ASCII.GetBytes(postData)
//Create an instance of a HttpRequest objec
HttpWebRequest objReq = (HttpWebRequest)WebRequest.Create(strURL)
//indicate that we will be posting the dat
hwreq.Method="POST"
hwreq.ContentType="application/x-www-form-urlencoded"
//send the for
objReq.AllowAutoRedirect=true
objReq.KeepAlive=false
objReq.ContentLength=buffer.Length
Stream objReqStream = objReq.GetRequestStream()
objStream.Write(buffer,0,buffer.Length)
HttpWebResponse objResp = (HttpWebResponse)objReq.GetResponse()
Stream objRespStream = objResp.GetResponseStream()
StreamReader sr = new StreamReader(objRespStream,Encoding.ASCII)
string strResult=sr.ReadToEnd()
The posted data (converted to the buffer above) contains the following string "TextBox1=Glenn Wilson&TextBox2=Developer
Does anyone know why my code appears not to work? It should be simple
Glenn
I have been trying to post data to a form on a web page using methods within the system.net namespace. I have followed all the documentation to the letter, but I just can't seem to post the form. The form has an event written in c# called Button1_Click. It seems that this event is not firing when the data is posted to the web form. The button is added to the page using <asp:Button id="Button1" runat="server" Text="Button1" OnClick="Button1_Click" /> The code used to submit the form is as follows
//encode the form data string into a byte arra
byte[] buffer = Encoding.ASCII.GetBytes(postData)
//Create an instance of a HttpRequest objec
HttpWebRequest objReq = (HttpWebRequest)WebRequest.Create(strURL)
//indicate that we will be posting the dat
hwreq.Method="POST"
hwreq.ContentType="application/x-www-form-urlencoded"
//send the for
objReq.AllowAutoRedirect=true
objReq.KeepAlive=false
objReq.ContentLength=buffer.Length
Stream objReqStream = objReq.GetRequestStream()
objStream.Write(buffer,0,buffer.Length)
HttpWebResponse objResp = (HttpWebResponse)objReq.GetResponse()
Stream objRespStream = objResp.GetResponseStream()
StreamReader sr = new StreamReader(objRespStream,Encoding.ASCII)
string strResult=sr.ReadToEnd()
The posted data (converted to the buffer above) contains the following string "TextBox1=Glenn Wilson&TextBox2=Developer
Does anyone know why my code appears not to work? It should be simple
Glenn