Forms

  • Thread starter Thread starter Prince
  • Start date Start date
P

Prince

Given the following HTML form

<form method="Post" action="www.xyz.com">
<input type="hidden" name="xxx" value="hello">
</form>

If I wanted to somehow, in the page behind form of an
ASP.NET page, write code that would send the value,
hello, to that site www.xyz.com, how would I do it?

I've been searching the newsgroup but no one has quite
given a concrete example. My guess is that I would use
the HttpWebRequest object. But how exactly would this be
done?

thanks,
Prince
 
That's just it, for POST, how do you set the body?

This is what I've done so far..

WebRequest req;
WebResponse result;
Stream requestStream;
Stream receiveStream;
Encoding encode;
StreamReader sr;

req = WebRequest.Create("https://www.xyz.com");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] b;
string postData = "xxx=hello";

StringBuilder urlEncoded = new StringBuilder();
urlEncoded.Append(postData);
b = System.Text.Encoding.UTF8.GetBytes(urlEncoded.ToString
());
req.ContentLength = b.Length;
requestStream = req.GetRequestStream();
requestStream.Write(b,0,b.Length);
requestStream.Close();

result = req.GetResponse();
receiveStream = result.GetResponseStream();
encode = System.Text.Encoding.GetEncoding("utf-8");
sr = new StreamReader( receiveStream, encode );

StringBuilder sb = new StringBuilder();
while( sr.Peek() >= 0 ){
sb.Append( sr.ReadLine() );
}


A lot of HTML source code is stored within the
StringBuilder. I'm not quite sure if that's coming from
the site I Posted to. The only way to find out is to
somehow make a call to Internet Explorer and have it
render the string stored in StringBuilder.

How do I send the info to a new IE process? I don't need
to control IE once the process has started. It can be
totally separte from my app.

Am I on the right track?

-- Prince
 
Back
Top