HTTP notes and summaries (1) Telnet sends HTTP GET and HTTP POST requests separately

Source: Internet
Author: User
Tags http post

To simplify the saying:

WebService = HTTP protocol + XML

Rest = HTTP protocol + Json

Various APIs = HTTP protocol + Xml/json to implement

HTTP Request Information Format

Request Line

A. request method : Get,post,put,delete,trace,options

B. request path (the requested resource, part of the URL)

C. protocol used

Request header information

Request principal Information

HTTP requests In addition to the browser, any other tool that satisfies the HTTP protocol can send HTTP requests, such as telnet(the Telnet protocol is a member of the TCP/IP protocol family and is the standard protocol and primary way of Internet remote login service):

Enter the IP address of the server to receive the HTTP request :

127.0.0.17 80

(If you are prompted: ' Telnet ' is not an internal or external command, and is not a running program, go to: " Control Panel" and "Programs"---> "turn Windows features on or off", and check "Telnet Client")

Press CTRL +] + Enter to turn on the Echo function (easy to debug);

Now that the Telnet client is connected to port 80, the request can be sent according to the HTTP protocol standard:

GET request, request/php/http/1.php This path, request with http/1.1 Protocol ( request line input complete), enter

Virtual directory is host:127.0.0.17 ( request header information entered completed)

Enter

Carriage return ( blank line : header information and body information (can not) be distinguished by a blank line)

The HTTP request and response are as follows:

HTTP Response Information Format

The response information in the following:

http/1.1 okdate:tue, Jul 13:04:57 gmtserver:apache/2.2.21 (Win32) php/5.3.10x-powered-by:php/5.3.10content- Length:5content-type:text/htmlhello

which

Response Line : http/1.1 OK

Response Line 3 parts: protocol version (http/1.1), Status code (+), status text (OK)

Response Header Information : formatted as

Key:value

Key:value

Key:value

...

Key:value

content-length: Length of theme

Blank Line

Response body Information : Hello

"Example" completes the POST request for HTTP with Telnet.

First write a PHP file 2.php:

1 <? PHP 2 /* 3     Writing the received POST data to text 4     requires telnet to request 5*/6$ Strimplode$_post); 7 file_put_contents $str. " \ r \ n ", file_append); 8 Echo ' Write success ';

Parsing: The format of an HTTP request

$ method $ PATH $ protocol

Request header Information

(Blank line)

Request principal Information

Attention:

the length of the body should be indicated in the header message. content-length and principal type Content-type application/x-www-form-urlencoded

post/php/http/2.php http/1.1Host: 127.0.0.17Content-type:application/x-www-form-  Urlencodedcontent-length:19username=dee&age=28http/1.1 OKDate: Tue, Jul 16:15:03 gmtserver: apache/2.2.21 (Win32) php/5.3.10X-powered-by:php/5.3.10Content- Length:13Content-type:text/htmlwrite success lost the connection to the host. C:\users\administrator>

which

main information : username=dee&age=28

At the same time Post.txt:

This completes the POST request and response.

HTTP notes and summaries (1) Telnet sends HTTP GET and HTTP POST requests separately

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.