Hypertext Transfer Protocol and HTTP packet

Source: Internet
Author: User
Tags microsoft iis

HTTP is used to send and receive messages over the Internet. HTTP is a request-response protocol. A client sends a request and the server returns the response to the request. All requests and responses are HTTP packets. The HTTP protocol uses reliable TCP connections. The default port is 80. The first version of HTTP is HTTP/0.9, which was later developed to HTTP/1.0. The latest version is HTTP/1.1. HTTP/1.1 is defined by RFC 2616.

In HTTP, the session between the client and server is always initialized by the client by establishing a connection and sending an HTTP request packet. The server does not actively contact the client or require a connection with the client. The browser and server can interrupt the connection at any time. For example, you can click "stop" to interrupt the current file download process and disable the HTTP connection to the Web server at any time when you browse the Web page.

1. http request package
HTTP request packets (get, post, and other request methods) are composed of three parts: method-Uri-Protocol/version, request header, and request body. The following is an example of an HTTP request package (get:

GET/index. jsp HTTP/1.1
Accept-language: ZH-CN
Connection: keep-alive
HOST: 192.168.0.106
Content-Length: 37

Username = new_andy & Password = new_andy

The first line of the request packet is method-Uri-Protocol/version:
Get is the request method. According to HTTP standards, HTTP requests can use multiple request methods. HTTP 1.1 supports seven request methods: Get, post, Head, options, put, delete, and trace. Common Request methods include get and post.

/Index. jsp indicates Uri. Uri specifies the network resource to be accessed.
HTTP/1.1 is the protocol and Protocol version.
The last line username = new_andy & Password = new_andy is the body, and the body is separated by an empty line (\ r \ n) in the HTTP header. Here, we need to describe one point. Content-Length indicates the length of the body. Some body lengths are not described in the header, but only indicate transfer-encoding: chunked. For details about how to calculate the length of the chunked type, see RFC 1626.
The request packet header also contains many useful information about the client environment and request body, which is not described here.

2. Http response packet
Similar to the HTTP request package, it consists of three parts: Protocol-statusCode-Description, response header, and response body. The following is an example of an HTTP response:

HTTP/1.1 200 OK
Server: Microsoft-Microsoft IIS/4.0
Date: Mon, 3 Jan 2005 13:13:33 GMT
Content-Type: text/html
Last-modified: Mon, 11 Jan 2004 13:23:42 GMT
Content-Length: 90

<HTML>
<Head>
<Title> example of interpreting HTTP packets </title> Hello world!
</Body>
</Html>

The first line of the HTTP response packet is similar to the first line of the HTTP request, indicating that the protocol used is HTTP 1.1, and the server processes the Request status code 200.
The Response Header also contains a lot of useful information like the request header, such as the server type, date and time, content type, and length. The response body is the HTML page returned by the server. The response header and body are also separated by CRLF.

Interpretation in Wiki

Hypertext Transfer Protocol(HTTP,Hypertext Transfer ProtocolIs the most widely used network transmission protocol on the Internet. All WWW files must comply with this standard. HTTP was designed to provide a method for publishing and receiving HTML pages.

Overview

The development of HTTP is the result of the collaboration between the World Wide Web society and the Internet team. The final version was determined in a series of RFC releases, the most famous of which was RFC 2616. The common version of HTTP/2616 is defined in RFC 1.1.

HTTP is a protocol used for requests and responses between the client and the server. An HTTP client, such as a web browser, initializes a request by establishing a connection to a special port of the remote host (the default port is 80. An HTTP server waits for the client to send a request sequence by listening to a special port, just like "get/HTTP/1.1" (used to request the default page of the Web server ), you can choose to receive mime message like an email. This message contains a large number of information headers used to describe all aspects of the request and respond to a selected retained data subject. After receiving a request sequence (If yes, there are still messages), the server will send back a response message, such as "200 OK" and send back a message of its own, the message body may be the requested file, error message, or other information.

HTTP is different from other TCP-based protocols, such as ftp. In HTTP, once a special request (or related sequence of requests) is completed, the connection is usually interrupted. This design makes HTTP perfect for the World Wide Web where the current page has rules to connect to another Server Page. When the lack of persistent connections is a required way to maintain the user status, web designers may encounter some problems. Most of these methods include the use of cookies.

Here is an HTTP secure version called https, which supports any encryption.AlgorithmAs long as this encryption algorithm can be understood by both parties on the page.

HTTP (and https) is located by a unique resource locator or URL. The syntax for creating such an address location is HTML link.

Example

The following is an example of an HTTP client session with the server running on www.google.com and port 80.

Client request:

 
Get, HTTP, 1.1
HOST: www.google.com

(Follow a line feed and press Enter)

Server Response:

 
HTTP/1.1 200 OK
Content-Length: 3059
Server: GWs/2.0.
Date: sat, 11 Jan 2003 02:44:04 GMT
Content-Type: text/html
Cache-control: Private
Set-COOKIE: Pref = id = 73d4aef52e57bae9: TM = 1042253044: LM = 1042253044: S = smcc_hrpcqiqy
X9j; expires = Sun, 17-Jan-2038 19:14:07 GMT; Path =/; domain = .google.com
Connection: keep-alive

(Followed by a blank line, and consists of HTML text to form Google's homepage)

In http1.0, the client sends a request to the server, and the server sends a response to the client. The connection is released. Http1.1 supports persistent connections. This allows the client to send a request and receive a response, and then quickly send another request and receive another response. Due to multiple additional requests, the TCP connection is not released, and the TCP load in each request is relatively small. At the same time, it is also possible to send multiple requests (usually two) before receiving the response from the previous request. This technology is called "Pipeline ".

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 810211

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.