HTTP protocol-request format and Method

Source: Internet
Author: User

 

I. http request format

When a browser sends a request to the Web server, it sends a data block to the server, that is, the request information. The HTTP request information consists of three parts:

① Request Method URI protocol/version

② Request Header)

③ Request body

The following is an example of an HTTP request:

GET/sample. jsp HTTP/1.1

Accept: image/GIF. Image/JPEG ,*/*

Accept-language: ZH-CN

Connection: keep-alive

HOST: localhost

User-Agent: Ila ila/4.0 (compatible; msie5.01; window nt5.0)

Accept-encoding: gzip, deflate

 

Username = Jinqiao & Password = 1234

 

(1) Request Method URI protocol/version

The first line of the request is "Method URL protocol version": Get/sample. jsp HTTP/1.1

In the above Code, "get" indicates the request method, "/sample. jsp" indicates the URI, and "HTTP/1.1 indicates the protocol and Protocol version.

According to HTTP standards, HTTP requests can use multiple request methods. For example, http1.1 supports seven request methods: Get, post, Head, options, put, delete, and tarce. In Internet applications, the most common methods are get and post.

The URL completely specifies the network resource to be accessed. Generally, you only need to give a relative directory relative to the root directory of the server. Therefore, it always starts with "/". Finally, the Protocol version declares the HTTP Version Used during communication.

(2) Request Header)

The request header contains many useful information about the client environment and request body. For example, the request header can declare the language used by the browser and the length of the Request body.

Accept: image/GIF. Image/JPEG .*/*

Accept-language: ZH-CN

Connection: keep-alive

HOST: localhost

User-Agent: Ila ila/4.0 (compatible: msie5.01: Windows nt5.0)

Accept-encoding: gzip, deflate.

(3) Request body

There is a blank line between the request header and the request body. This line is very important. It indicates that the request header has ended and the request body is followed.. The request body can contain the query string information submitted by the customer:

Username = Jinqiao & Password = 1234

In the preceding HTTP request, the request body contains only one line of content. Of course, in actual applications, the HTTP Request body can contain more content.

Iv. HTTP Request Method: Get post

1) Get Method

The get method is the default HTTP request method. We use the get method to submit form data. However, the form data submitted by the get method is only encoded, at the same time, it will be sent to the Web server as part of the URL. Therefore, if you use the get method to submit form data, there is a security risk. For example

Http: // 127.0.0.1/login. jsp? Name = zhangshi & age = 30 & submit = % CC % E + % BD % bb

From the preceding URL request, you can easily recognize the content submitted by the form. (? In addition, because the data submitted by the get method is a part of the URL request, the amount of data submitted cannot be too large.

2) Post Method

The post method is an alternative to the get method. It mainly submits form data to the Web server, especially a large volume of data. The post method overcomes some shortcomings of the get method. When the form data is submitted through the POST method, the data is not part of the URL request but is transmitted to the Web server as standard data, which overcomes the disadvantages of the information in the get method being unable to be kept confidential and the data volume is too small. Therefore, for security considerations and respect for user privacy, the POST method is usually used for form submission.

From the programming perspective, if you submit data using the get method, the data is stored in the QUERY_STRING environment variable, and the data submitted by the POST method can be obtained from the standard input stream.

Method

Description

Get

Simple requests to server resources

Head

Similar to a GET request, but the returned response does not contain specific content. It is used to obtain the header.

Post

Used to send requests that contain user submitted data

Put

A version of the current request document

Delete

Sends a request to delete a specified document.

Trace

Send a copy of the request to track its processing process

Options

Returns all available methods. You can check which methods are supported by the server.

Connect

Proxy-based requests for SSL Tunneling

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.