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设置的更多相关文章

  1. Jsoup问题---获取http协议请求失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.

    Jsoup问题---获取http协议请求失败 1.问题:用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不 ...

  2. Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.

    用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不符合要求. 请求代码如下: private static ...

  3. 转载 SharePoint【Site Definition 系列】– 创建Content Type

    转载原地址:  http://www.cnblogs.com/wsdj-ITtech/archive/2012/09/01/2470274.html Sharepoint本身就是一个丰富的大容器,里面 ...

  4. the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header

    the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header ...

  5. ajax使用向Spring MVC发送JSON数据出现 org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported错误

    ajax使用向Spring MVC发送JSON数据时,后端Controller在接受JSON数据时报org.springframework.web.HttpMediaTypeNotSupportedE ...

  6. Jmeter发送post请求报错Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

    常识普及: Content-type,在Request Headers里面,告诉服务器,我们发送的请求信息格式,在JMeter中,信息头存储在信息头管理器中,所以在做接口测试的时候,我们维护Conte ...

  7. Jsoup获取部分页面数据失败 Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml

    用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不符合要求. 请求代码如下: private static ...

  8. Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

    Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported告诉你,你的请求头是application/x- ...

  9. {"timestamp":"2019-11-12T02:39:28.949+0000","status":415,"error":"Unsupported Media Type","message":"Content type 'text/plain;charset=UTF-8' not supported","path":&quo

    在Jmeter运行http请求时报错: {"timestamp":"2019-11-12T02:39:28.949+0000","status&quo ...

  10. SharePoint自动化系列——Add content type to list.

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 将创建好的content type(若是跨web application需要事先publish c ...

随机推荐

  1. 打通 Spark 系统运行内幕机制循环流程

    本课主题 打通 Spark 系统运行内幕机制循环流程 引言 通过 DAGScheduelr 面向整个 Job,然后划分成不同的 Stage,Stage 是从后往前划分的,执行的时候是從前往后执行的,每 ...

  2. spring的声明式事务,及redis事务。

    Redis的事务功能详解 http://ghoulich.xninja.org/2016/10/12/how-to-use-transaction-in-redis/ MULTI.EXEC.DISCA ...

  3. C#中的"?"和"??"

    摘自:http://www.cnblogs.com/zxjyuan/archive/2009/10/27/1590795.html 如果你看到C#中的“?”问号脑袋里便充满问号,那么这个贴子便是为你而 ...

  4. BIND简易教程(3):DNSSec配置

    目录:BIND简易教程(1):安装及基本配置BIND简易教程(2):BIND视图配置BIND简易教程(3):DNSSec配置 (本篇) DNSSec,有个半英半中的名字叫DNS安全扩展.说的好听一点, ...

  5. Html 列表实现展开和收起

    HTML中,点击列表元素,在其下展开更多的小选项.不点的时候是收起来的.就是实现路由器左边的菜单那样的功能.怎么实现,知道的指点一下,谢谢了!! 最常见的方法是通过Javascript控制某标签的CS ...

  6. js获取昨天今天和明天

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/UP19910522/article/details/30028299 <html> &l ...

  7. 检测Android和IOS

    var u=navigator.userAgent; var isAndroid=u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; / ...

  8. 微信小程序开发工具快捷键

    格式调整 //保存文件 Ctrl+S //代码行缩进 Ctrl+[, Ctrl+] //折叠打开代码块 Ctrl+Shift+[, Ctrl+Shift+] //复制粘贴,如果没有选中任何文字则复制粘 ...

  9. 51Nod - 1205 (流水先调度)超级经典的贪心 模板题

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1205 N个作业{1,2,…,n}要在由2台机器M1和M2组成 ...

  10. POJ 1644 分苹果 (递归解法)

    把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法. Input 第一行是测试数据的数目t(0 <= t < ...