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的值了。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM