先看下HttpClient在微软官方的解释:
这个类中的方法有多个,现在主要讲 SendAsync(HttpRequestMessage request)的用法;
示例代码:
1 var httpRequestMessage = new HttpRequestMessage 2 { 3 Method = HttpMethod.Post, 4 RequestUri = new Uri("http://192.168.0.37:54543/API/WeChat/GetXX"), 5 Content = new StringContent(data.ToJson(), Encoding.UTF8, "application/json") 6 }; 7 var resp = await httpClient.SendAsync(httpRequestMessage); 8 string resp_body = await resp.Content.ReadAsStringAsync();
注意点是data.ToJson()的参数必须保证与被请求端一致(检查了许久这个问题)