5 minutes to make you understand the HTTP protocol

Source: Internet
Author: User
Tags ranges

First, HTTP Introduction 1.http protocol Introduction
    1. The HTTP protocol (hypertext Transfer Protocol, Hypertext Transfer Protocol) is one of the most widely used network transmission protocols on the Internet, and all WWW files must abide by this standard.
    2. HTTP is based on TCP/IP communication protocol to pass data (HTML files, image files, query results, etc.)
    3. 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. Such as
    4. HTTP is an application-layer protocol that consists of requests and responses and is a standard client server model. HTTP is a stateless protocol.
    5. The port number for the HTTP default port number is 80,https 443.
2.http Protocol Workflow

An HTTP operation is called a transaction, and its working process is probably as follows:

    1. The user in the browser type the URL that needs to visit the webpage or click a link in a webpage;
    2. Browser according to the domain name in the URL, through the DNS to resolve the destination Web page IP address;
浏览器请求这个页面:http://hackr.ip/index.html在这一步,需要域名系统DNS解析域名hackr.ip,得主机的IP地址 20X.189.105.112。然后将上面结合本机自己的信息,封装成一个http请求数据包
    1. Before HTTP starts working, the client first establishes a link to the server via the TCP/IP protocol (TCP three-time handshake)
    2. After the connection is established, the client sends a request to the server in the form of a Uniform Resource Identifier (URL), a protocol version number, followed by MIME information including the request modifier, client information, and content.
    3. After 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. In general, once the Web server sends the request data to the browser, it closes the TCP connection, and then if the browser or server joins the line in its header, the Connection:keep-alive TCP connection remains open after it is sent, and the browser can continue to send the request over the same connection. Maintaining a connection saves the time it takes to establish a new connection for each request and also saves network bandwidth.

2.1 Short Connections

The procedure for a short connection is to establish a connection--data transfer--to close the connection ... Establish connection--data transfer--close connection

If customer requests are frequent, more time and bandwidth will be wasted on TCP setup and shutdown operations.

2.2 Long Links

Long link, refers to a connection can be continuously sent multiple packets, during the connection hold, if no packet sent, need to send a link detection packet.

Long link operation step: Establish connection--data transfer ... (Keep connected) ... Data transfer--close connection

Long connection eliminates more TCP setup and shutdown operations, reduces waste and saves time

Long links are divided into without pipelining and with pipelining, without pipelining, where the client sends a new request only after receiving the response from the previous request.

2.3 Pipeline

Is with pipelining, you can send the next request after each link is established without waiting for the request to come back

3. HTTP Request messages

The client sends an HTTP request to the server for a request message that includes the following format:

Request line, request header (header), request body composition, the general format of the request message is given.

请求行:    方法:        GET 获取资源        POST 向服务器端发送数据,传输实体主体        PUT 传输文件        HEAD 获取报文首部        DELETE 删除文件        OPTIONS 询问支持的方法        TRACE 追踪路径    协议/版本号    URL    请求头:    通用首部(General Header)    请求首部(Request Header)    响应首部(Response Header)    实体首部(Entity Header Fields)    请求体

Request Message Disassembly:

3.1 GET Request

3.2 POST Request

4. HTTP response Messages

The HTTP response consists of a response line, a response header, and a response body.

响应行    (HTTP/1.1)表明HTTP版本为1.1版本,状态码为200,状态消息为(ok)响应头    Date:生成响应的日期和时间;    Content-Type:指定了MIME类型的HTML(text/html),编码类型是ISO-8859-1响应体

Response Message Disassembly:

5. HTTP status Code
category cause
1XX Informational (Informational status code)
2XX Success (Success status code)
3XX Redirection (redirected)
4XX Client error (Customer fault status code)
5XX Server error (bad state of servers)
5.1 2XX Success
200(OK 客户端发过来的数据被正常处理204(Not Content 正常响应,没有实体206(Partial Content 范围请求,返回部分数据,响应报文中由Content-Range指定实体内容
5.2 3XX redirect
301(Moved Permanently) 永久重定向302(Found) 临时重定向,规范要求,方法名不变,但是都会改变303(See Other) 和302类似,但必须用GET方法304(Not Modified) 状态未改变, 配合(If-Match、If-Modified-Since、If-None_Match、If-Range、If-Unmodified-Since)307(Temporary Redirect) 临时重定向,不该改变请求方法
5.3 4XX Client Error
400(Bad Request) 请求报文语法错误401 (unauthorized) 需要认证403(Forbidden) 服务器拒绝访问对应的资源404(Not Found) 服务器上无法找到资源
5.4 5XX server-side error
500(Internal Server Error)服务器故障503(Service Unavailable) 服务器处于超负载或正在停机维护
6. First 6.1 General header fields
header Field name Description
Cache-control Controlling caching behavior
Connection Management of links
Date Message Date
Pragma Message Instructions
Trailer The header of the message tail
Trasfer-encoding Specify the transmission encoding method of the message body
Upgrade Upgrade to another protocol
Via Proxy Server information
Warning Error notification
6.2 Request Header Field
header Field name Description
Accept Media types that the user agent can handle
Accept-charset Preferred Character Set
Accept-encoding Priority encoding
Accept-langulage Preferred language
Authorization Web authentication Information
Expect Expecting specific behavior of the server
From User's e-mail address
Host The server on which the request resource resides
If-match Compare entity Tags
If-modified-since Compare update times for resources
If-none-match Compare entity Tags
If-range A range request that sends an entity byte when the resource is not updated
If-unmodified-since Compare update times for resources (as opposed to if-modified-since)
Max-forwards Maximum Transfer hop count
Proxy-authorization Proxy server requires client authentication
Range Entity byte range Request
Referer The original acquiring party of the URI in the request
TE Priority of transfer encoding
User-agent Information for HTTP client programs
6.3 Response Header Field
header Field name Description
Accept-ranges Whether to accept byte ranges
Age When the resource was created
ETag Matching Information for resources
Location Client redirects to the specified URI
Proxy-authenticate Proxy Server authentication information for the client
Retry-after Time to send the request again
Server Information about the server
Vary Management information for Proxy server caching
Www-authenticate Server-to-client authentication
6.4 Entity Header Field
header Field name Description
Allow Supported HTTP methods for resources
Content-encoding How entities are encoded
Content-language Natural language of the entity
Content-length The content size of the entity (in bytes)
Content-location URI that overrides the corresponding resource
Content-md5 Message Summary for Entities
Content-range The position range of the entity
Content-type Media type for entity Principal
Expires Entity Expiration Time
Last-modified Last modified time of resource

Reference:

    1. Introduction to HTTP
    2. HTTP protocol Detailed
    3. HTTP
    4. HTTP working process



5 minutes to make you understand the HTTP protocol

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.