[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保存 ...
随机推荐
- [转帖]为应用程序池“XXX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误。该进程 ID 为“XXXX”。数据字段包含错误号。
[终极解决方案]为应用程序池“XXX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误.该进程 ID 为“XXXX”.数据字段包含错误号. ...
- <generatePublisherEvidence> 元素
<configuration> <runtime> <generatePublisherEvidence enabled="false"/> & ...
- 基于Vue cli生成的Vue项目的webpack4升级
前面的话 本文将详细介绍从webpack3到webpack4的升级过程 概述 相比于webpack3,webpack4可以零配置运行,打包速度比之前提高了90%,可以直接到ES6的代码进行无用代码剔除 ...
- codeforces932E Team Work
题目链接:CF932E 由第二类斯特林数知 \[ n^m=\sum_{i=0}^nS(m,i)*i!*\dbinom{n}{i} \] \[ \begin{aligned} \sum_{i=1}^n ...
- Codeforces Round #549 (Div. 2) 训练实录 (5/6)
The Doors +0 找出输入的01数列里,0或者1先出完的的下标. Nirvana +3 输入n,求1到n的数字,哪个数逐位相乘的积最大,输出最大积. 思路是按位比较,从低到高,依次把小位换成全 ...
- Vue(四)组件
组件的复用 这里的工程和上一节的一样 先建立一个组件 MyButton.vue <template> <button @click="count++">Yo ...
- showdoc app接口文档编写利器
通过朋友介绍,才知道有这么好的一个在线接口编写文档开源项目,非常感谢原作者的贡献 ShowDoc介绍 关于ShowDoc的介绍,请访问:http://blog.star7th.com/2015/11/ ...
- STL初始化initializer_list
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h&g ...
- cucumber测试项目报错
[INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building th ...
- 快速掌握Nginx(二) —— Nginx的Location和Rewrite
1 location详解 1.location匹配规则 Nginx中location的作用是根据Url来决定怎么处理用户请求(转发请求给其他服务器处理或者查找本地文件进行处理).location支持正 ...