c#的http请求工具类核心代码

//post请求
var values = new Dictionary<string, string>
{
    { "thing1", "hello" },
    { "thing2", "world" }
};

var content = new FormUrlEncodedContent(values);

var responseString = client.PostAsync("http://www.example.com/recepticle.aspx", content).Content.ReadAsStringAsync().Result;
//get请求
var responseString = client.GetStringAsync("http://www.example.com/recepticle.aspx").Result;

 

 

原文:https://stackoverflow.com/questions/4015324/how-to-make-an-http-post-web-request

posted @ 2020-11-27 08:12  凌心缘  阅读(283)  评论(0编辑  收藏  举报