G
Guest
Hello All:
I cannot seem to get a simple programmatic post to work. From one ASPX
page, I want to generate HTML from another page. Thus, I programatically
post to the second page and read the response. However, my posted data is
always null in the second page. Can anyone tell me why this doesn't work?
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
"http://localhost/page2.aspx");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
string dataToPost = "name=Goober";
byte [] bytes = System.Text.Encoding.ASCII.GetBytes(dataToPost);
request.ContentLength = bytes.Length;
System.IO.Stream request_stream = request.GetRequestStream();
request_stream.Write(bytes, 0, bytes.Length);
request_stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.IO.Stream response_stream = response.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader
(response_stream);
I cannot seem to get a simple programmatic post to work. From one ASPX
page, I want to generate HTML from another page. Thus, I programatically
post to the second page and read the response. However, my posted data is
always null in the second page. Can anyone tell me why this doesn't work?
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
"http://localhost/page2.aspx");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
string dataToPost = "name=Goober";
byte [] bytes = System.Text.Encoding.ASCII.GetBytes(dataToPost);
request.ContentLength = bytes.Length;
System.IO.Stream request_stream = request.GetRequestStream();
request_stream.Write(bytes, 0, bytes.Length);
request_stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.IO.Stream response_stream = response.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader
(response_stream);