Recently ready to touch PHP socket programming, so be prepared to consolidate the knowledge previously learned, here is a simple review of the use of Telnet to simulate HTTP requests.
1. Set up the http.php file in the directory pointed to in Port 80 first
2. In terminal input Telenet 127.0.0.1 80
Ps:windows doc command line: Ctrl + '] ' key enters input mode, then press ENTER to switch to explicit input mode (can display input characters)
Simulate GET requests
#在刚才建立的http. php file to print GET request Parameters Print_ ($_get);
#请求方式 Request Address Protocol
GET /test.php?a=1 http/1.0host:127.0.0.1
After entering 2 returns, you can see the printed get parameter a = 1, as well as some header information.
It is important to note that the http/1.1 version must be added to the host, and the http/1.0 will not be added.
Simulate a POST request
#在刚才建立的http. php file to print the POST request parameters generated file File_put_contetns (' post.php ', Var_export ($_post,true));
#需要加上 the method of the request and the length of the body of the message.
post/test.php http/1.0host:localhostcontent-type:application/x-www-form-urlencodedcontent-length:16name= Lemon&age=23
Open post.php to see Name=>lemon, age=2. Because the message body length is set to 16.
Simulating HTTP requests with Telnet