POST to a webpage from C# app
Posted
by markiyanm
on Stack Overflow
See other posts from Stack Overflow
or by markiyanm
Published on 2010-05-17T15:19:34Z
Indexed on
2010/05/17
15:31 UTC
Read the original article
Hit count: 177
I've been looking/asking around and can't seem to figure this one out. I have a C# application and need to be able to gather some data in the app, pop open a web browser and POST some data to it.
I can POST to the site from within the app fine and I can obviously pop open IE to a certain link but I can't do both. I can't POST to that link directly. Any ideas on how to accomplish this?
private void btnSubmit_Click(object sender, EventArgs e)
{
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "Fullname=Test";
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://www.url.com/Default.aspx");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
System.Diagnostics.Process.Start(myRequest.Address.ToString()); //open browser
newStream.Close();
}
Any insight would be greatly appreciated.
Thanks
© Stack Overflow or respective owner