实例操作工具使用telnet
cmd 下telnet localhost 80 再按Ctrl 加 ] ,最后按下回车,输入请求
(注)
在Http1.1中,协议中必须要有请求行和Host请求头,如果是http1.0中则不必要加入Host
GET /test.html HTTP/1.0
Host:
GET方式传递时,数据量有限制,一般在1KB以下
实例
GET /test.php?username="mr.zxing"&password="123456" HTTP/1.1
Host:
php 代码
<span style="font-size: medium;"><?php
if($_GET['username'] || $_GET['password']){
print $_GET['username'];
print "\n";
print $_GET['password'];
}
</span>
POST提交
POST /test.php HTTP/1.1
Host:
Content-Type: application/x-www-form-urlencoded
Content-Length:39
username=mr.zxing&password=123456
如果传递的数据大于39,信息POST不会马上发送会等到数据等于你给定的长度后再发送,当小于39时返回的数据会被截取
php代码
<span style="font-size: medium;">if($_POST){
print $_POST['username'];
print "\n";
print $_POST['password'];
}</span>
