开发者

How to POST using WebRequest?

Using WebRequest How to POST things, Should I use GetRequestStream? and ho开发者_C百科w to format POST string

Thanks


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");
}


As an alternative to HttpWebRequest, have a look at WebClient.UploadValues:

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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜