HTTP protocol Overview

Source: Internet
Author: User

HTTP protocol Overview URI (Uniform Resource Identifier)

Used to identify specific server resources on the network, with URIs in two forms, url and urn, respectively:

URL (Uniform Resource Locator)

URLs are currently the most widely used form of a URL that describes a specific location of a resource on a particular server. The resources here can be just one file, page, picture and so on.

The standard URL format is defined as follows:

<scheme>://<user>:<password>@#<frag>

scheme
uses the protocol (for example, HTTP (s), FTP, RTSP) URI. Scheme
user Some protocols require a username (such as an FTP protocol) URI. UserInfo
password user name corresponding to the password URI. UserInfo the host name or IP address URI of the
host server. Host
Port Server Listener Port number (HTTP defaults to 80,https default is 443) URI. Port
path The local name of the resource on the server, also known as the relative path URI. Absolutepath
params input parameters for some protocols, such as containing multiple uses; separating URIs. Absolutepath
query parameters for some protocols, the HTTP protocol generally uses & separates multiple parameters URIs. Query
frag

A reference to a specific resource within a page, typically used to specify a specific paragraph.

is used for client use, and the server side ignores the field

URI. Fargment

Common protocol URLs:

Http://cnblogs.com/qlluo/default.html#URL

Ftp://qlluo:[email Protected]/resource/info.txt

Protocol Standard please refer to: rfc1738

URN (Uniform Resource Name)

The biggest difference between a urn and a URL is that the urn does not need to specify a specific location for the resource, she identifies a particular content on the network. The protocol is more advanced than it is currently used and is not specifically introduced here.

HTTP messages

Describes the most common flow of HTTP messages, the message sent to the server by the client is called a request message, and the message sent to the client by the server is called the corresponding (response) message.

It is customary to define the flow of messages from upstream (upstream) to downstream (downstream), which is used when referring to proxy servers.

PS: There is no absolute rigorous definition of client and server side, it is generally said that the one party that sends the request is the client, listening to a particular port waiting for the connection to be the server side.

Requests (Request)

The HTTP request message consists of the starting line, the header, and the entity body three parts:

<method> <request-URL> <version>         //start line 

Start line

The start line includes the method, the request URL, and the version number three parts:

1. Method: Indicates the type of operation the client wants the server to perform, common get, POST, delete, etc.

2. Request URL: Represents the resource that the client needs to request, typically an absolute URL.

3. Version number: Indicates the HTTP version of the message, the format is http/<major>.<minor> The current mainstream version is http/1.1

GET http://www.cnblogs.com/HTTP/1.1

First

The header includes some specific key-value pairs that explain some of the properties of the request message.

The header consists of 0 lines or more lines, separated by CRLF (\ r \ n) between each row. Each row is separated by a colon with a name and a value, followed by an optional space after the colon.

The header is terminated by a blank line.

content-type:text/plaincontent-length:50

The HTTP protocol pre-defines a number of headers for implementing the underlying and extended capabilities of the protocol. In general, a valid HTTP request message will contain multiple headers.

Entity body

An entity body can contain a block of arbitrary text data and may not contain entity principals for certain methods (GET, HEAD).

The format of the entity body is determined by the upper layer protocol and is constrained by Content-type, Content-length, content-encoding.

The following is a request message to visit the home page of the garden, which ignores some of the uncommon headers.

GET http://www.cnblogs.com/HTTP/1.1connection:keep-aliveuser-agent:mozilla/5.0 (Windows NT 10.0; Win64; x64) applewebkit/537.36 (khtml, like Gecko) chrome/54.0.2840.71 safari/537.36accept:text/html,application/ xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Accept-encoding:gzip, deflate, sdchaccept- language:en-us,en;q=0.8
corresponding (Response)

The corresponding message of HTTP consists of the starting line, the first, and the entity body three parts:

<version> <status> <reason-phrase><entity-body>

Start line

The starting line consists of the version number, the status code, and the reason phrase three parts:

1. Version number: Indicates the HTTP version of the message, the format is Http/<major>.<minor>, the current mainstream version is http/1.1, and the request message version number format.

2. Status code: Use a three-digit number to describe the status of the corresponding message (success, error, etc.), the following table describes the classification of status codes, followed by the common status code.

td> The most common success status code is 200, which indicates a successful request The
status code range Predefined range category explanation
100-199 100-101 Message prompt  
200-299 200-206 Success
300-399 300-307 redirect

is typically used with a location header to indicate that the resource has been moved permanently or temporarily to the URL specified by the place.

Common redirection status codes are 301,304,307

400-499 400-417 Guest The user-side error

Indicates that the client sent a request to the server with an error.

Common (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found)

500-599 500-505 server-side error

Indicates that an error occurred during the processing of the request by the server side.

Common (Internal Server Error), 503 (Services unavailable)

3. Reason phrase: A phrase describing the status code in # #, which is interpreted as a readable version of the status code.

http/1.1 OK

First

The format is identical to the header of the HTTP request message, but contains different header content

Entity body

The format is consistent with the entity body of the HTTP request message and is used to host the content of the response.

Common response entity bodies include: pages, js,css, images, files, JSON, or XML text.

The following is a response message to the home page of the garden, which omits most of the entity body content.

 http/1.1 200 okcontent -type:text/html; charset=utf-8connection:keep -alivelast -modified:wed, Jan 2017 05:06:04< Span style= "COLOR: #000000" > gmtcontent -length:45005<! DOCTYPE html> " ZH-CN " Span style= "COLOR: #800000" > " >"  utf-8   "/> <meta name="  viewport   " Content= " width=device-width, initial-scale=1  /> <title> Blog Park-Developer's online home </title> ...  

This article mainly introduces the most basic, most commonly used protocols and message parts of HTTP protocol. The continuation of the Assembly provides an in-depth overview of HTTP headers, status codes, connection mechanisms, proxies, caches, and authentication-related content.

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.