Posting using C#

  • Thread starter Thread starter Amir Ghezelbash
  • Start date Start date
A

Amir Ghezelbash

Hello all,

I would like to know how to i can post to a page using the server behind
code ...same exact posting as you would do say if you had a form in your
html file...is it possible
what i have is this but doesnot seem to be working




string url = BuildLink();
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(server);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte [] bytes = System.Text.Encoding.ASCII.GetBytes(url);
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();


Any help would greatly be appriciated
 
Amir said:
Hello all,

I would like to know how to i can post to a page using the server
behind code ...same exact posting as you would do say if you had a
form in your html file...is it possible
what i have is this but doesnot seem to be working




string url = BuildLink();
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(server);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte [] bytes = System.Text.Encoding.ASCII.GetBytes(url);
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();

You have to call req.GetResponse() to actually send the request and
retrieve and the server's response.

Cheers,
 
Back
Top