http post Content-type: application/json; charset=utf-8


 

The header just denotes what the content is encoded in. It is not necessarily possible to deduce the type of the content from the content itself, i.e. you can‘t necessarily just look at the content and know what to do with it. That‘s what HTTP headers are for, they tell the recipient what kind of content they‘re (supposedly) dealing with.

Content-type: application/json; charset=utf-8 designates the content to be in JSON format, encoded in the UTF-8 character encoding. Designating the encoding is somewhat redundant for JSON, since the default (only?) encoding for JSON is UTF-8. So in this case the receiving server apparently is happy knowing that it‘s dealing with JSON and assumes that the encoding is UTF-8 by default, that‘s why it works with or without the header.

Does this encoding limit the characters that can be in the message body?

No. You can send anything you want in the header and the body. But, if the two don‘t match, you may get wrong results. If you specify in the header that the content is UTF-8 encoded but you‘re actually sending Latin1 encoded content, the receiver may produce garbage data, trying to interpret Latin1 encoded data as UTF-8. If of course you specify that you‘re sending Latin1 encoded data and you‘re actually doing so, then yes, you‘re limited to the 256 characters you can encode in Latin1.

当指定

Content-type: application/json;

时,默认编码就是utf-8,不需要额外指定

时间: 2024-10-07 18:08:41

http post Content-type: application/json; charset=utf-8的相关文章

org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported

踩到了一个神坑,明明@RequestMapping注解并没有设置consumes,即没有限定请求参数的类型.却出现文章底部的错误,原因竟然是同一个model下注解了两个@JsonBackReference. @Entity // 用户 public class User extends IDomain { @Column(columnDefinition = "varchar(255) comment '[电话]'") private String phone; @Column(col

org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported或其他Content type不支持处理

很久没从头到尾搭框架,今天搭的过程中,springmvc controller方法入参用@RequestBody自动绑定参数时一直提示各种 not supported 排查问题有两个解决路径: 1)使用post协议提交时,请检查Content type类型,如: $.ajax({ type: "POST", contentType: "application/json;charset=UTF-8", url: "/reg", data: JSON

SpringMVC在使用JSON时报错信息为:Content type 'application/json;charset=UTF-8' not supported

直接原因是:我的(maven)项目parent父工程pom.xml缺少必要的三个jar包依赖坐标. 解决方法是:在web子模块的pom.xml里面添加springMVC使用JSON实现AJAX请求. <!--spring mvc-json依赖--> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifact

Spring MVC 前后台传递json格式数据 Content type &#39;application/x-www-form-urlencoded;charset=UTF-8&#39; not supported

报错如下: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported 解决方案: 引入如下包: 问题既解决. Spring MVC 前后台传递json格式数据 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

Content type &#39;application/x-www-form-urlencoded;charset=UTF-8&#39; not supported for @RequestBody XXX

问题描述 前端使用ajax发送post请求发送Json数据,spring mvc报Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported for @RequestBody XXX错误 解决办法 1.重新组装数据 var params=JSON.stringify({param1:param1}); 2.ajax请求设置 dataType: "json", data: param, cont

解决&quot;415 Cannot process the message because the content type &#39;application/x-www-form-urlencoded&#39; was not the expected type &#39;text/xml; charset=utf-8&#39;&quot;

wcf basicHttpBinding content-type    text/xml;charset=utf-8 wsHttpBinding  'application/soap+xml; charset=utf-8' webHttpBinding 'application/x-www-form-urlencoded'   对应网页中的post请求 所以如果是post请求wcf服务,要使用webHttpBinding 解决"415 Cannot process the message be

postman测试接口报Content type &#39;text/plain;charset=UTF-8&#39; not supported解决方法

增加一个请求头管理器,添加content-type:application/json.并将请求修改为json数据传输试试. 参考:https://zhidao.baidu.com/question/1644957725975214740.html postman测试接口报Content type 'text/plain;charset=UTF-8' not supported解决方法 原文地址:https://www.cnblogs.com/xiaoni-fighting/p/12298436.

【记录】ajax 设置请求header的Content-Type 为 application/json;charset=utf8

具体案例如下 $.ajax({ url: context.state.IpccSendIm, method: 'POST', data: JSON.stringify(val), headers:{'Content-Type':'application/json;charset=utf8'}, dataType:"json", success: function (data) { console.log(data); imStore.addChatMsgDemo({ msg: { ro

解决“Resource interpreted as Document but transferred with MIME type application/json”问题

在上传图片时,使用ajax提交,返回的数据格式为json.在测试时发现IE浏览器中,上传图片后,没有显示图片,而是弹出一个提示:是否保存UploadImg.json文件:而在其他浏览器中正常. 在Chrome中调试后发现,图片上传成功后,浏览器给出了一个警告:Resource interpreted as Document but transferred with MIME type application/json. 原来后台代码在返回json数据时,响应数据的ContentType默认为"a