The HTTP protocol is used to send and receive messages on the Internet. The HTTP protocol is a request-to-answer protocol-client sends a request, the server returns the response of the request, and all requests and answers are HTTP packages. The HTTP protocol uses a reliable TCP connection, and the default port is 80. The first version of HTTP is http / 0.9, and later developed to HTTP / 1.0, and now the latest version is HTTP / 1.1. HTTP / 1.1 is defined by RFC 2616. In HTTP, the session between Client / Server is always initialized by the client by establishing a connection and sending an HTTP request package, the server does not actively contact the client or requires connection to the client. Browsers and servers can interrupt the connection at any time, for example, when browsing the web, you can click the "Stop" button to interrupt the current file download process, turn off the HTTP connection with the web server. 1 HTTP Request Packet HTTP Request Packet (GET, POST, etc.) consists of three parts, namely: method -uri-protocol / version, request head, request body. Below 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 package is the method -uri-protocol / version: GET is the request method, according to the HTTP standard, the HTTP request can use a variety of request methods. HTTP 1.1 supports seven request methods: GET, POST, HEAD, OPTIONS, PUT, DELETE, and TRACE, etc., commonly used for requesting methods GET and POST. /index.jsp represents the URI. URI specifies the network resources to access. HTTP / 1.1 is the version of the agreement and protocol. The last line Username = new_andy & password = new_andy is the body, and the body is separated from the HTTP header. Here, you need to explain, where content-length illustrates the length of the body, and some body lengths are not described in the header, just indicate Transfer-Encoding: chunked. See RFC 1626 about the length calculation method of the chunked type. The header of the request package will also contain a lot of useful information about the client environment and the request text, which is no longer described. 2 The HTTP response package and HTTP request package are similar, consisting of three parts, respectively: protocol - status code - description, response, response body. Below is an example of an HTTP response:
HTTP / 1.1 200 ok
Server: 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
Hello World!
body>
html>
The first line of the HTTP response package is similar to the first line of the HTTP request, indicating that the protocol used is HTTP 1.1, and the server processing requested status code 200. The response should also contain many useful information as the request head, such as server type, datetime, content type, and length. The body of the response is the HTML page returned by the server. The response head and the body are also separated by CRLF. Explanation in Wiki
Hypertext Transfer Protocol (HTTP, Hypertext Transfer Protocol) is the most widely used network transport protocol on the Internet. All WWW files must be observed. Design HTTP initial purpose is to provide a method of publishing and receiving an HTML page.
Overview
The development of HTTP is the result of the World Wide Web Association and the Internet Working Group, which determines the final version in a series of RFC releases, where the most famous is RFC 2616. HTTP / 1.1 is defined in RFC 2616 This version of the generally used today.
HTTP is a protocol for requests and answers between clients and servers. An HTTP client, such as a web browser, initializes a request by establishing a connection to a remote host special port (default port 80). An HTTP server sends a request sequence by listening to a special port waiting for the client, just like "get / http / 1.1" (used to request the default page of the web server), select the same MIME message like Email, this message is included in this message A large number of information head sequences for requesting all aspects, responding to a selected reserved data body. After receiving a request sequence (if necessary, if there is a message), the server will send back a reply message, such as "200 ok", send back a message, this message may be the requested file, Error message or some other information.
HTTP is different from other TCP-based protocols such as FTP. In HTTP, once a special request (or the relevant sequence of requests) is complete, the connection is usually interrupted. This design makes the HTTP is perfect for the current page to connect to another server page to another server page. When the lack of persistent connection is a necessary choice for maintaining the user status, it will accidentally generate some problems for web designers. Most of these methods include the use of "cookies".
Here, there is a security version of HTTP is called HTTPS, HTTPS supports any encryption algorithm, as long as this encryption algorithm can be understood by both parties.
HTTP (and HTTPS) is located by a unique resource locator or a referred to as URLS. Creating the syntax of this address location for HTML links.
example
Below is an example of a session between an HTTP client and a server, running at www.google.com, port 80
Client request:
Get / http / 1.1host: www.google.com
(Following a wrap, realizing the carriage return)
Server Answer:
HTTP / 1.1 200 OKContent-Length: 3059Server: GWS / 2.0Date: Sat, 11 Jan 2003 02:44:04 GMTContent-Type: text / htmlCache-control: privateSet-Cookie: PREF = ID = 73d4aef52e57bae9: TM = 1042253044: LM = 1042253044: S = SMCC_HRPCQIQYX9J; Expires = Sun, 17-JAN-2038 19:14:07 gmt; path = /; domain = .google.comconnection: Keep-Alive
(Followed by an empty line, and the text of the HTML format consists of Google's homepage) In HTTP 1.0, the client sends a request to the server, and the server sends a response to the client. Thereafter, the connection will be released. On the other hand, HTTP 1.1 supports persistent connections. This allows the client to send a request and receive a response, and then quickly sends another request and receive another response. Because of multiple additional requests, the TCP connection is not released, and each request is relatively small about TCP load. At the same time, it is possible to send multiple requests (usually two) before obtaining a response from the previous request. This technology is called "pipeline".