HttpClient的Content-Type设置
Posted zzr-stdio
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HttpClient的Content-Type设置相关的知识,希望对你有一定的参考价值。
HttpClient的Content-Type设置
最近在对接公司内容的一个云服务的时候,遇到一个问题,就是如果使用HttpClient如何设置post时候的Content-Type?
public static string PostAdminSelect(string start)
{
string url = $"{BaseUrl}admin/select";
Model.AdminSelectQuery adminSelectQuery = new Model.AdminSelectQuery();
adminSelectQuery.start = start;
string res = adminSelectQuery.ToJson();
StringContent stringContent = new StringContent(res);
stringContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
string result = httpClient.PostAsync(url, stringContent).Result.Content.ReadAsStringAsync().Result;
return result;
}
这样就可以随意的设置Content-Type的值了。
以上是关于HttpClient的Content-Type设置的主要内容,如果未能解决你的问题,请参考以下文章