Problem Programatically Posting to an ASPX PAge

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);
 
G

Guest

Robert,
I don't see anything wrong with your code. Why not try using the simplified
WebClient.UploadData method? Put a breakpoint in the Page_Load handler of the
receiving page and examine the Request.Form or Request.Params collections.
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,829
Messages
2,569,737
Members
45,525
Latest member
RosalindSa

Latest Threads

Top