你的位置:首页 > ASP.net教程

[ASP.net教程][笔记]服务端的GET、POST请求


 

程序集 System.Net.Http.dll

目标框架要在 .NET framework 4.5 以上才行

 

POST:

HttpClient httpClient = new HttpClient();

HttpContent httpContent = new StringContent("{\"name\":\"张三\",\"age\":\"18\"}");
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

string json = httpClient.PostAsync("http://19.88.200.128:8081/api/v1/security/login", httpContent)
.Result.Content.ReadAsStringAsync().Result;

 

 

GET:

HttpClient httpClient = new HttpClient();

string json = httpClient.GetAsync("http://19.88.200.128:8081/api/v1/security/login?name=张三&age=18")
.Result.Content.ReadAsStringAsync().Result;