概述

在POST请求中,理论上请求端程序可以发送任意格式报文正文,但是最好在报文头Content-Type字段标明正文的格式,方便接收端根据Content-Type正确处理正文。

传统HTML-form表单提交

html-form表单中,post正文格式被定义在enctype属性中,该属性一共定义了3个值,分别对应Content-Type的3个值:

enctype值 enctype描述 对应Content-Type的值 正文段格式示例
application/x-www-form-urlencoded 在发送前编码所有字符,http_query编码方式(默认) application/x-www-form-urlencoded manid=qwert&file-a=1ca6f20fd0c29742bec9914423140d03.jpg
multipart/form-data 不对字符编码,正文内容是每一个表单字段进行boundary分隔组成的报文,支持二进制数据提交 multipart/form-data; boundary=XXXXXXXXXX(请求端程序自行生成的boundary) ------WebKitFormBoundaryNOdBuEzJYqyffk3l
Content-Disposition: form-data; name="manid"

qwert
------WebKitFormBoundaryNOdBuEzJYqyffk3l
Content-Disposition: form-data; name="file-a"; filename="1ca6f20fd0c29742bec9914423140d03.jpg"
Content-Type: image/jpeg

#¥%%……&%F……%

------WebKitFormBoundaryNOdBuEzJYqyffk3l--

text/plain 空格转换为 "+" 加号,但不对特殊字符编码 text/plain manid=qwert
file-a=1ca6f20fd0c29742bec9914423140d03.jpg

只有enctype="multipart/form-data"能够提交form input type="file"字段选择的文件,其余两种编码方式只能够提交文件名。

自定义提交

发送端只需要遵循HTTP报文规范,就可以自行自定义发送post报文,这跟是否带有Content-Type无关,但是接收端也要自定义解析规则,如果是通用的解析规则,通常只能支持规范中的Content-Type类型解析。

PHP

PHP自带的报文解析只支持html form enctype原生的前2种解析方式("application/x-www-form-urlencoded","multipart/form-data"),通常字符类型的字段解析到全局变量$_POST中,二进制内容解析到全局变量$_FILES中。

也可以运用自带封装协议"php://input"读取请求正文,但是当enctype="multipart/form-data"的情况下,这种方式是无效的,其余情况,包括自定义的Content-Type值,都可以读取。

[HTTP]POST报文中Content-Type对正文解析的影响的更多相关文章

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

    开始 controller 方法写的是 @RequestMapping( value = "/add", method = RequestMethod.POST ) public ...

  2. jmeter报"msg":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported"的解决方法

    1.报"msg":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supporte ...

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

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

  4. xml文件报Element 'beans' cannot have character [children],because the type's content type is element

    写springMvc.xml文件时,偶然遇到 Element 'beans' cannot have character [children],because the type's content t ...

  5. 遇到问题之“postman报Unsupported Media Type: Content type 'text/plain;charset=UTF-8' not supported”

    postman报Unsupported Media Type: Content type 'text/plain;charset=UTF-8' not supported postman之所以报Uns ...

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

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

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

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

  8. Springs Element 'beans' cannot have character [children], because the type's content type is element-only

    Springs Element 'beans' cannot have character [children], because the type's content type is element ...

  9. 响应http报文中的Date属性与cookie过期时间的关系

    今天在測试.net时,发现一个莫名其妙的问题:cookie老是保存不到浏览器端; 经过细致的比对成功与不成功的报文,居然无意中发现好像Date与它有关系,这太让我意想不到了,从来不知道cookie保存 ...

随机推荐

  1. [安全转帖]浅析安全威胁情报共享框架OpenIOC

    浅析安全威胁情报共享框架OpenIOC https://www.freebuf.com/sectool/86580.html Indicator of compromise Outline: 1. I ...

  2. [转帖]Ansible管理windows集群

    Ansible管理windows集群 http://www.cnblogs.com/Dev0ps/p/10026908.html 写的挺好的 我关注点还是不够好呢 最近公司新项目需要安装400+win ...

  3. ZooKeeper连接并创建节点以及实现分布式锁操作节点排序输出最小节点Demo

    class LockThread implements Runnable { private DistributedLock lock; public LockThread(int threadId, ...

  4. wx.request 使用数据

    小程序中,怎么使用wx.request返回的数据??? 在你的js页面中 主要是这句话 var that=this; 为什么呢?因为使用过jquery的ajax的朋友都知道.在ajax函数中的this ...

  5. Django_rest framework 框架介绍

    restful介绍  restful协议 一切皆是资源,操作只是请求方式 URL 设计 原先的URL设计方式 在url 中体现出操作行为 /books/ books /books/add/ addbo ...

  6. 简单 php 代码跟踪调试实现

    简单 php 代码跟踪调试实现 debug_backtrace:生成回溯 debug_print_backtrace:打印回溯 1. debug_backtrace ($options = DEBUG ...

  7. HTML&CSS_基础04

    一.常见的选择器 1. 元素选择器 选择页面中指定的元素 2. id选择器 语法:#id属性值{} 3. 类选择器 语法:.class属性值{} 可以为同一个元素设置多个属性值,多个值之间用空格隔开 ...

  8. CENTOS手动安装修复python ,YUM CENTOS手动安装修复YUM

    CENTOS手动安装修复YUM  2019年3月8日  杨宇 Comments 0 Comment 目录 [hide] 一.问题场景 二.手动修复 2.1 下载 rpm 包 2.2 安装 rpm 包 ...

  9. css控制table间距

    border-collapse: separate;border-spacing: 20px 30px; /* 水平间距 垂直间距 */

  10. Java集合的总结

    参考博客: http://www.jianshu.com/p/63e76826e852 http://www.cnblogs.com/LittleHann/p/3690187.html https:/ ...