2010-04-11 51 views

回答

12
var request = WebRequest.Create("http://www.example.com"); 
request.Method = "POST"; 
request.ContentType = "application/x-www-form-urlencoded"; 
using (var writer = new StreamWriter(request.GetRequestStream())) 
{ 
    // write to the body of the POST request 
    writer.Write("param1=value1&param2=value2"); 
} 
7

作爲替代HttpWebRequest的,看看WebClient.UploadValues

var values = new NameValueCollection(); 
values.Add("param1", "value1"); 
values.Add("param2", "value2"); 

new WebClient().UploadValues("http://www.example.com", values);