Post表单——Content-Type字段
HTML表单是一种常见的机制,可以使web应用程序以灵活的形式收集输入,接收用户输入。表单通常用post方法提交,请求头中包含一个Content-Type字段,这个字段不同值对应请求主体的不同形式,下面将分别展示:
1. Content-Type: application/x-www-form-urlencoded
POST http://127.0.0.1/exam5/admin/logincheck.php HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Referer: http://127.0.0.1/exam5/admin/login.html
Content-Type: application/x-www-form-urlencoded
Content-Length: 29
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Host: 127.0.0.1
username=admin&password=admin
Content-Type: application/x-www-form-urlencoded规定消息主体中的内容类型为 application/x-www-form-urlencoded,这表示和URL查询字符串中的一样,消息主体中的内容也以名-值对表示。如本例中的:username=admin&password=admin
2.Content-Type: multipart/form-data
Content-Type还可以为Content-Type: multipart/form-data; boundary=---------------------------1570849584953;这在文件上传功能中比较常见。应用程序可在表单标签的enctype属性中要求浏览器使用多部分编码。使用这种编码形式,请求中的Content-type消息头还会指定一个随机的字符串,用它了分割请求主体中的参数。举例如下:
POST http://127.0.0.1/exam5/file.php?type=file&method=upload HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Referer: http://127.0.0.1/exam5/file.php?type=file&method=upload
Content-Type: multipart/form-data; boundary=---------------------------1570849584953
Content-Length: 205
Cookie: PHPSESSID=9r1qhre9cub35c5jp2mauitsa7
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Host: 127.0.0.1
-----------------------------1570849584953
Content-Disposition: form-data; name="upfile"; filename="1.txt"
Content-Type: text/plain
<php?
phpinfo();
>
-----------------------------1570849584953--