HTTP protocol Overview

Source: Internet
Author: User

1.1 Introduction

HTTP is an abbreviation for the Hyper Text Transfer Protocol (Hypertext Transfer Protocol). HTTP was originally designed to provide a way to publish and receive HTML pages.

Carrier: message

______|______

|      | |

start line header body

Procedure: Connection, request -and- response disconnect

1. support client / server mode.

2. Simple and quick: When a client requests a service from the server, it simply transmits the request method and path. The request method commonly has get,HEAD,POST. Each method specifies a different type of contact between the customer and the server. Because the HTTP protocol is simple, the HTTP server's program size is small, so the communication speed is fast .

3. Flexibility: HTTP allows any type of data object to be transmitted. The type being transmitted is marked by Content-type .

4. No connection: The meaning of no connection is to limit the processing of only one request per connection . When the server finishes processing the customer's request and receives the customer's answer, the connection is disconnected. In this way, the transmission time can be saved.

5. No status : The HTTP protocol is a stateless protocol. Stateless means that the protocol has no memory capacity for transactional processing . A lack of state means that if the previous information is required for subsequent processing, it must be re-routed, which may cause the amount of data to be transferred per connection to increase. On the other hand, it responds faster when the server does not need the previous information.

1.2 location in the TCP/IP protocol stack

The HTTP protocol is usually hosted on top of the TCP protocol, sometimes hosted on the TLS or SSL protocol layer, which is what we often call HTTPS.

HTTPS(full name:Hyper Text Transfer Protocol over secure Socket Layer) is a security-targeted HTTP channel, simply http Security edition.

That is, the SSL layer is added under HTTP, the security base of HTTPS is SSL, so the detailed content of encryption needs SSL.

The main differences between HTTPS and HTTP are the following four points:

First, the HTTPS protocol requires a certificate to the CA, the general free certificate is very small and requires a fee.

Second, HTTP is a Hypertext Transfer Protocol, the information is plaintext transmission, HTTPS is a secure SSL encryption Transfer protocol.

Third, HTTP and HTTPS use a completely different way of connection, with the same port, the former is 80, the latter is 443.

Four, HTTP connection is very simple, is stateless; The HTTPS protocol is a network protocol built by the SSL+HTTP protocol to encrypt the transmission and authentication, which is more secure than the HTTP protocol.

As shown in the following:

1.3 Request Response model for HTTP

The HTTP protocol is always a client-initiated request, and the server echoes the response.

This limits the use of the HTTP protocol, which cannot be implemented when the client does not initiate a request, the server pushes the message to the client. The HTTP protocol is a stateless protocol, and there is no correspondence between this request and the last request of the same client.

Push (polling) the representation of the push is actually the client timed request server.

1. Polling: The client periodically sends an AJAX request to the server, returning the response information and closing the connection as soon as the server receives the request.

Pros: It's easier to write back-end programs.

Cons: Half of the requests are useless, wasting bandwidth and server resources.

Example: suitable for small applications.

2. Long polling: The client sends an AJAX request to the server , the server receives a request to hold the connection until a new message returns the response information and closes the connection, and the client finishes processing the response and sends a new request to the server.

Advantage: No more frequent requests in the absence of messages.

Disadvantage: Server hold connections consume resources.

Example: Webqq,Hi web version,Facebook IM.

In addition, there is a distinction between long connections and socket connections:

1. Long connection: Embed a hidden iframe in the page , set the src attribute ofthis hidden iframe to A long connection request, and the server can continuously input data to the client.

Advantage: Instant message arrives without unwanted request.

Disadvantage: The server maintains a long connection that increases overhead.

Example: Gmail Chat

2.Flash socket: Embed a flash program JavaScript in the page that uses the socket class by calling this Flash program to provide the socket interface communicates with the server-side socket interface,and JavaScript controls the display of the page after it receives the information sent from the server side.

Pros: Realize real instant communication, not pseudo-instant.

Disadvantage: The client must be installed Flash Plugin, non- HTTP protocol, cannot automatically traverse firewalls.

Example: Network interactive game.

1.4 Work Flow

An HTTP operation is called a transaction, and its working process can be divided into four steps:

1) first the client and the server need to establish a connection . As soon as you click on a hyperlink, the HTTP work begins.

2) After the connection is established, the client sends a request to the server in the form of a Uniform Resource Identifier (URL), protocol version number, followed by MIME information including the request modifier, client information, and possible content.

3) when the server receives the request, it gives the corresponding response information in the form of a status line, including the protocol version number of the information, a successful or incorrect code, followed by MIME information including server information, entity information, and possible content.

4) The client displays the response message and then the client disconnects from the server . If an error occurs in one of the steps above, the information that generates the error is returned to the client, with the display output. For the user, these processes are done by HTTP itself, the user just click with the mouse, waiting for information to display it.

1.5 HTTP Messages

a message is a data unit that is exchanged and transmitted in a network, that is, a data block to be sent by the site at once. The message contains the complete data information to be sent, the length of which is inconsistent, unlimited and variable.

Message Flow

An HTTP message is a block of data that is sent between HTTP applications. These blocks start with meta-information (meta-information) in textual form that describes the content and meaning of the message, followed by an optional data section. These messages flow between the client, the server, and the agent.

Message Composition

an HTTP message consists of 3 parts, namely:

(1), start line (start lines)

A. Request line

Request a message request the server to do some operations on the resource. The starting line of the request message, or the request line, the package

contains a method and a request URL, this method describes what the server should do, request a URL

describes which resource to execute this method on. The request line also contains the version of HTTP , which is used to inform the service

What kind of client is using the HTTP.

All of these fields are delimited by whitespace .

B. response Lines

The response message carries the status information and all the result data generated by the operation and returns it to the client. Response Report

The starting line of the text, or the response line, contains the HTTP version , number status code , to

And a reason phrase that describes the textual form of the operation status .

All of these fields are delimited by whitespace .

(2), first < header > (header)

A. Common header

Each HTTP header has a simple syntax: The name is followed by a colon (:), followed by an optional null

, followed by the field value, and finally a CRLF.

The HTTP specification defines several header fields. The application is also free to invent its own header.

Common Header Instances

B. The first continuation line

Dividing a long header line into multiple lines can improve readability by having at least one space before each line.

table symbol (tab).

For example:

http/1.0 OK

Content-type:image/gif

content-length:8572

Server:test Server

Version 1.0

(3), body (body)

The third part of the HTTP message is the optional entity body part. The body of the entity is the payload of the HTTP message.

is what HTTP is about to transfer.

HTTP messages can host many types of digital data: pictures, videos, HTML documents, software applications

Credit card transactions, e-mail, and more.

Here is an example of a message

Message Syntax

This is the format of the request message:

<method> <request-URL> <version>

<entity-body>

This is the format of the response message (note that only the syntax of the starting line is different):

<version> <status> <reason-phrase> eg: http/1.0 OK

<entity-body>

HTTP protocol Overview

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.