测试用代码:
<form method="POST"> First name: <input type="text" name="fname" /> Last name: <input type="text" name="lname" /> <input type="submit" value="Submit" /> </form>
使用GET时传送给服务的数据:
GET /phpsocket/method.php?fname=steven&lname=jobs HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */* Referer: http://localhost/phpsocket/method.php?fname=steven&lname=jobs Accept-Language: zh-cn Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E) Host: localhost Connection: Keep-Alive
使用POSTT时传送给服务的数据:
POST /phpsocket/method.php HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */* Referer: http://localhost/phpsocket/method.php Accept-Language: zh-cn Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E) Host: localhost Content-Length: 23 Connection: Keep-Alive Cache-Control: no-cache Cookie: ZDEDebuggerPresent=php,phtml,php3 fname=steven&lname=jobs
两者比较结果:
1. GET提交时网址发生了变化,POST提交时网址没有变化;
2. GET数据以网址QueryString的方式提交给服务器,POST数据以Content的方式提交给服务器。