首页 > Web开发 > 详细

.net Core System.Net.Http.HttpClient 发送post请求

时间:2020-06-04 22:00:10      阅读:185      评论:0      收藏:0      [点我收藏+]

 

string url = "http://www.xxx.com/api/postmsg";

string jsonContent = JsonConvert.SerializeObject(message);

using (var client = new HttpClient())
{
var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
//上面代码使http Content-Type 为 application/json; charset=utf-8。如果希望Content-Type为application/json,可以使用下面两行代码
//content.Headers.Remove("Content-Type"); // "{application/json; charset=utf-8}"
//content.Headers.Add("Content-Type", "application/json");

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer");
string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
}

.net Core System.Net.Http.HttpClient 发送post请求

原文:https://www.cnblogs.com/shiyilang398/p/13045802.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!