[HTTP]POST报文中Content-Type对正文解析的影响
概述
在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 #¥%%……&%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对正文解析的影响的更多相关文章
- springboot 报错 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
开始 controller 方法写的是 @RequestMapping( value = "/add", method = RequestMethod.POST ) public ...
- 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 ...
- Jmeter发送post请求报错Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
常识普及: Content-type,在Request Headers里面,告诉服务器,我们发送的请求信息格式,在JMeter中,信息头存储在信息头管理器中,所以在做接口测试的时候,我们维护Conte ...
- 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 ...
- 遇到问题之“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 ...
- Jsoup问题---获取http协议请求失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.
Jsoup问题---获取http协议请求失败 1.问题:用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不 ...
- Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.
用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不符合要求. 请求代码如下: private static ...
- 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 ...
- 响应http报文中的Date属性与cookie过期时间的关系
今天在測试.net时,发现一个莫名其妙的问题:cookie老是保存不到浏览器端; 经过细致的比对成功与不成功的报文,居然无意中发现好像Date与它有关系,这太让我意想不到了,从来不知道cookie保存 ...
随机推荐
- MySql插入点数据
DROP PROCEDURE IF EXISTS pre;delimiter $$ CREATE PROCEDURE pre ()BEGIN DECLARE i INT DEFAULT 1 ;WHIL ...
- nodejs fs path
内容详见我的gitHub: https://github.com/shangyueyue/ssy-utils/tree/master/src/nodejs/fs
- React Native & app demos
React Native & app demos https://github.com/ReactNativeNews/React-Native-Apps https://github.com ...
- slf4j+log4j2模式的日志搭建
前言:今天打算为大家介绍一下我们我们在项目中必须得有的一个部分——日志!是的,就是那些让我们看着头疼的东西~~~好的日志可以帮助团队成员快速发现并解决问题,用好了可以大幅度提高代码缺陷修复效率!言归正 ...
- wiki leaks file link url
wiki leaks file link url XXX发表于2010-08-07 15:54:56 原始来源:http://www.wikileaks.org/wiki/Category:China ...
- vue stylus 格式化问题
IDE是vscode 安装了.vetur插件 由于stylus可以仅用缩进不用写大括号之类的,所以十分方便, 但有个问题,按alt shift F 格式化时,vetur这个插件会默认添加上正常css的 ...
- LVS负载均衡DR模式实现
LVS负载均衡之DR模式配置 DR 模式架构图: 操作步骤 实验环境准备:(centos7平台) 所有服务器上配置 # systemctl stop firewalld //关闭防火墙 # sed - ...
- nginx 提示the "ssl" directive is deprecated, use the "listen ... ssl" directive instead
该问题是由于新版nginx采用新的方式进行监听https请求了 解决方式 在listen中改为 listen 443 ssl; 删除ssl配置 # ssl on; 完美解决: 解决完成前后的配置如下 ...
- IIS搭建校内小站
背景 在学校读书最大的烦恼是去机房忘了带作业,或者带了U盘传文件又很容易丢,或者的或者用学校内网网盘又容易忘了上传. 所以笔者搞了个办法. IIS准备工作 win+pause break 打开控制面板 ...
- linux查看主板型号、CPU、显卡、硬盘等信息
系统 uname -a # 查看内核/操作系统/CPU信息 head -n 1 /etc/issue # 查看操作系统版本 cat /proc/cpuinfo # 查看CPU信息 hostname # ...