Simulating HTTP requests with Telnet

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.