环境:widows和linux都可以,只是windows下效果不好。本文以在linux下进行
目的:让你了解应用层协议HTTP,手动方式敲协议。
用telnet建立连接后,就可以手动实现协议。telnet不仅可以连接服务端的23端口,也可以连接其他端口,例如:21,25,80等。
GET 页面
1、与baidu建立http连接
输出
- fym@G470:~/www/public_html/test$ telnet www.baidu.com 80
- Trying 61.135.169.125...
- Connected to www.a.shifen.com.
- Escape character is '^]'.
2、发送GET请求首页内容
输入上面这行内容后,要敲两次回车键。然后你就可以看见百度给你返回的首页内容了。
POST 上送数据
服务端的php代码,formaction.php
- <?php
- import_request_variables(gp,"formval_");
- echo "name = ".$formval_name;
- echo "<br />";
- echo "age = ".$formval_age;
- ?>
telnet 主机后,POST数据
- fym@G470:~/www/public_html/test$ telnet fym.vacau.com 80
- Trying 31.170.161.196...
- Connected to fym.vacau.com.
- Escape character is '^]'.
- POST /test/formaction.php HTTP/1.1
- HOST: fym.vacau.com
- Content-Type: application/x-www-form-urlencoded
- Content-Length: 15
-
- name=fym&age=26
服务端回送数据
- HTTP/1.1 200 OK
- Date: Sat, 09 Jun 2012 04:15:38 GMT
- Server: Apache
- X-Powered-By: PHP/5.2.17
- Content-Length: 178
- Connection: close
- Content-Type: text/html
-
- name = fym<br />age = 26
GET
- fym@G470:~/www/public_html/test$ telnet fym.vacau.com 80
- Trying 31.170.161.196...
- Connected to fym.vacau.com.
- Escape character is '^]'.
- GET /test/formaction.php?name=fym&age=26 HTTP/1.1
- HOST: fym.vacau.com