Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HttpWebRequest req = (HttpWebRequest)
- WebRequest.Create("http://mysite.com/index.php");
- req.Method = "POST";
- req.ContentType = "application/x-www-form-urlencoded";
- string postData = "var=value1&var2=value2";
- req.ContentLength = postData.Length;
- StreamWriter stOut = new
- StreamWriter(req.GetRequestStream(),
- System.Text.Encoding.ASCII);
- stOut.Write(postData);
- stOut.Close();
- using (WebClient client = new WebClient ())
- {
- //manipulate request headers (optional)
- client.Headers.Add (HttpRequestHeader.UserAgent, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
- //execute request and read response as string to console
- using (StreamReader reader = new StreamReader(client.OpenRead(targetUri)))
- {
- string s = reader.ReadToEnd ();
- Console.WriteLine (s);
- }
- }
Add Comment
Please, Sign In to add comment