HTTP protocol Fine Solution

Source: Internet
Author: User
Tags http request

A question-and-answer interaction between a Web server and a browser must also follow certain rules, which is the HTTP protocol. It is an application layer protocol in the TCP/IP protocol set that defines the process of exchanging data between browsers and Web servers and the format of the data itself. The most widely used http/1.1 relative to http/1.0 is that it supports continuous connections.

1.http/1.0 Session Mode:

Establish a connection, send request information
-------------------------------------------------------------------------->
Client Server
<--------------------------------------------------------------------------
Close connection, echo response message

Each connection handles only one request, and the browser and Web server establish a separate connection, even for each page of the same Web site.

2.http/1.1 Session Mode:

Establish a connection, 1th request information
-------------------------------------------------------------------------->
............
Send Nth Request Information
-------------------------------------------------------------------------->
Client loopback 1th Time Response server
<--------------------------------------------------------------------------
..............
Respond to n-th response
<--------------------------------------------------------------------------
Send Shutdown connection request
-------------------------------------------------------------------------->
Close connection
<--------------------------------------------------------------------------

http/1.1 supports persistent connections that allow multiple HTTP requests and responses to be delivered on a single TCP connection, reducing the consumption and latency of establishing and closing connections. Multiple requests and responses to a Web page file that contains many images can be transmitted in one connection, but the requests and responses to each individual Web page file still need to use their connection, allowing the client to send the next request without waiting for the last request result to return.

Format of HTTP messages:
A complete request message includes a request line, a number of message headers, and the entity content.
A complete response message includes a status line, a number of message headers, and the entity content.
This is a simple introduction to the previous one. Here are a few more detailed explanations for these sections:
1. Request line: Includes three parts, that is, the request method, the resource path, and the HTTP protocol version used. The syntax is as follows: Request method resource Path HTTP version number <crlf>, where <CRLF> represents a combination of the two characters, carriage return and newline. HTTP request methods include post,, OPTIONS, DELETE, Trace, and put. The first two are commonly used.
2. Status line: Includes the version number of the HTTP protocol, a status code, and textual information describing the status code.
The syntax is as follows: HTTP version number status code reason narration <CRLF>

To pass parameters using GET and post:
After the URL address, you can attach some parameters, each of which consists of parameter names and values, separated by =, each parameter is separated by &, and the URL address and the entire parameter are used. Delimited, as follows:
http://www.it315.org/servlet/ParamsServlet?param1=aaa&param2=bbb
The amount of data used to pass parameters with get is limited, typically limited to less than 1KB. Using post is much larger than get. There is no limit to it. However, you must set the Content=type message header to ' application/x-www-form-urlencoded ' and set the length of the content-length message header as the entity content.

Response Status Code:
200: All normal, return is the normal request result.
404: The resource requested on the client is not present on the server, the status code is most common when browsing the Web page.

General Information Header:
Cache-control: This field is used to inform the proxy server between the client and the server how to use the cached page.
Connection: Specifies whether the client and server will continue to remain connected after processing this request/response.
Date: Used to represent the current time that an HTTP message was generated.
Transfer-encoding: The transfer encoding used to specify the content of the entity.

Request headers:
Accept: Used to specify the MIME types that the client program can handle. Multiple times are separated by commas.
Accept-charset: Indicates the character set that the client program can use. Multiple times are separated by commas.
Accept-encoding: Specifies the way that the client can decode data encoding. Multiple times are separated by commas.
Accept-language: Specifies which country language documents the client expects the server to return. Multiple times are separated by commas.
Host: Specifies the hostname and port number where the resource resides.

Response header:
Accept-range: Used to indicate whether the current Web server accepts units for the data specified in range requests and range requests.
Location: Used to inform the client of which new address to get the document. Because the current response does not directly return the content to the client, HTTP messages using the location header should not have entity content, so the two headers of location and Contect-type cannot appear in the message header at the same time.

Entity headers:
Allow: Used to specify the request method supported by the resource requested by the client.
Content-encoding: The compression encoding used to specify the content of the entity.
Content-language: Specifies the national language type for the returned Web page document.
Content-length: Used to specify the length of the entity content.
Content-location: The actual location path used to specify the content of the entity encapsulated in the response message.
Content-type: The MIME type used to specify the content of an entity. By checking the MIME type in this field of the server response message, the client knows the data format of the entity content and knows how to process it. The Web.xml file in the Conf directory under the <Tomcat> installation directory defines a number of types.
Last-modified: Used to specify the last modification time for a document.

Extension headers:
Refresh: This field tells the browser how often to refresh. Reproduced

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.