最近在对接公司内容的一个云服务的时候,遇到一个问题,就是如果使用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的值了。

相关文章:

  • 2022-12-23
  • 2021-04-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-18
  • 2022-12-23
  • 2021-07-16
  • 2021-11-01
相关资源
相似解决方案