HTTP请求编码格式与报文
2018-02-22 10:25
190 查看
HTTP请求的编码格式有很多中,这里主要记述一些常用的。
application/x-www-form-urlencoded:窗体数据被编码为名称/值对。(默认)。空格转换为 “+” 加号,但不对特殊字符编码。
multipart/form-data:窗体数据被编码为一条消息,页上的每个控件对应消息中的一个部分。
text/plain:窗体数据以纯文本形式进行编码,其中不含任何控件或格式字符。
JSON:以纯文本形式进行编码,其格式为JSON。
现有HTML代码如下:用属性enctype的值来区分Content-Type
当Content-Type为不同值时,报文结果分别为下:
此报文分割符为:boundary=—-WebKitFormBoundarys70zFPQBqcgHeMy9
application/x-www-form-urlencoded:窗体数据被编码为名称/值对。(默认)。空格转换为 “+” 加号,但不对特殊字符编码。
multipart/form-data:窗体数据被编码为一条消息,页上的每个控件对应消息中的一个部分。
text/plain:窗体数据以纯文本形式进行编码,其中不含任何控件或格式字符。
JSON:以纯文本形式进行编码,其格式为JSON。
现有HTML代码如下:用属性enctype的值来区分Content-Type
<form action="http://localhost:8080" method="post" enctype="application/x-www-form-urlencoded"> <input type="text" name="userName" value="zhan gsan"/> <input type="text" name="password" value="password"/> <input type="file" name="resultFile" /> <input type="submit" value="submit"/> </form>
当Content-Type为不同值时,报文结果分别为下:
Content-Type=application/x-www-form-urlencoded
浏览器用x-www-form-urlencoded的编码方式把form数据转换成一个字串(name1=value1&name2=value2…),然后把这个字串append到url后面,用?分割,加载这个新的url。 当action为post时候,浏览器把form数据封装到http body中,然后发送到server。POST / HTTP/1.1 Host: localhost:8080 Connection: keep-alive Content-Length: 62 Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 Origin: null Content-Type: application/x-www-form-urlencoded User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate, br Accept-Language: zh-CN,zh;q=0.9 userName=zhan+gsan&password=password&resultFile=dddddddddd.vlx
Content-Type=multipart/form-data
浏览器会把整个表单以控件为单位分割,并为每个部分加上Content-Disposition(form-data或者file),name(控件name)等信息,并加上分割符(boundary)。此报文分割符为:boundary=—-WebKitFormBoundarys70zFPQBqcgHeMy9
POST / HTTP/1.1 Host: localhost:8080 Connection: keep-alive Content-Length: 659 Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 Origin: null Content-Type: multipart/form-data; boundary=----WebKitFormBoundarys70zFPQBqcgHeMy9 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate, br Accept-Language: zh-CN,zh;q=0.9 ------WebKitFormBoundarys70zFPQBqcgHeMy9 Content-Disposition: form-data; name="userName" zhan gsan ------WebKitFormBoundarys70zFPQBqcgHeMy9 Content-Disposition: form-data; name="password" password ------WebKitFormBoundarys70zFPQBqcgHeMy9 Content-Disposition: form-data; name="resultFile"; filename="dddddddddd.vlx" Content-Type: application/octet-stream {"nodes":[{"name":"11111","image":"theme/gast/ren.png","entityId":"1000001"},{"name":"5555","image":"theme/gast/ren.png","entityId":"1000001"}],"edges":[{"source":"11111","target":"5555","relation":"ssss","count":"1","currentExtDepth":"1"}]} ------WebKitFormBoundarys70zFPQBqcgHeMy9--
Content-Type=text/plain
POST / HTTP/1.1 Host: localhost:8080 Connection: keep-alive Content-Length: 66 Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 Origin: null Content-Type: text/plain User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate, br Accept-Language: zh-CN,zh;q=0.9 userName=zhan gsan password=password resultFile=dddddddddd.vlx
相关文章推荐
- HTTP请求、响应报文格式
- 微信小程序请求后台服务器并向后台传数据的http请求格式的编码
- HTTP请求、响应报文格式
- HTTP请求、响应报文格式
- (转)( 精品)HTTP请求、响应报文格式
- http报文中chunked分块编码传输格式分析及c语言解压实现
- HTTP请求、响应报文格式
- [http请求]——请求方法与报文头格式
- 关于HTTP请求和响应报文格式
- RTP报文格式、各种参数意义、编码速率计算
- python2.7中关于编码,json格式的中文输出显示
- 使用WFetch查看HTTP请求、响应报文
- 短信猫开发之短信编码格式
- DNS报文格式
- 编码格式简介:ASCII码、ANSI、GBK、GB2312、GB18030和Unicode、UTF-8,BOM头
- java文件读写操作指定编码格式[转]
- JSON编码格式提交表单数据详解
- Oracle 编码格式 及其 char Varchar Varchar2的区别
- 常见编码格式
- 关于图片中的位之一 位图格式、编码与显象原理