Problem Programatically Posting to an ASPX PAge



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

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.IO.Stream response_stream = response.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader


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.

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