HTTP protocol Learning Summary

Source: Internet
Author: User

This article is a summary of the basics of learning the HTTP protocol these days. The content includes the principles of the HTTP protocol, HTTP request information and HTTP response information, and HTTP protocol status code.

1, the basic principle of the HTTP protocol : A client sends a request to the server, the service side of the request processing, the client accordingly. As shown in.

Figure 1 schematic diagram of the HTTP protocol

Here is a sample code for a simple request and response:

Client Request:

Service-Side response:

http/1.1 OK Date:fri, 4 Jul gmtserver:apachelast-modified:fri, Agu 02:02:20 Gmtetag 5bae1-16a-46d776ac "connection:closecontent-type:text/htmlcontent-length:362 Empty Line (CR+LF)<HTML>          <Head></Head><Body>.....--content 362Bytes ....</Body></HTML>

2. HTTP request

A. Request message format:

----------------------------------------------------------

Request Line ↔get/http/1.1

Request header Information ↔host:localhost

...

...

...

Blank Line (CR+LF)

[Request body information] (can not)

-----------------------------------------------------------

B. Description:

→ Request Line: Request method + Request Path +http protocol version

Request method: Get,post,head,option,delete,put, etc.

Request Path:/

HTTP protocol version: http/0.9 http/1.0 http/1.1

→ Request header information

Host: Requested hostname (localhost)

Note: The host field information must be included in the request header information because there may be multiple virtual hosts under the same IP address, and host is required to specify which host under that IP is requested.

Accept: The types of files that the client can handle. (Text/html,text/plain,image/jpeg)

Accept-encoding: Content encoding and priority order supported by User agent (gzip,deflate,compress)

Accept-charset: Character set and priority order supported by User agent (ISO-8859-5)

Referer: A URI that informs the server of the original resource request (this field can be used for anti-theft chaining)

Example: referer:http://www.baidu.com

User-agent: Communicates information such as browser and user agent name for creating requests

3. HTTP response

A. Response message format

-------------------------------------------------

Response Line ↔http/1.1 OK

Response header Information ↔server:apache

...

...

...

Blank Line (CR+LF)

[Response body Information] (can not)

--------------------------------------------------

B. Description:

→ Response line: HTTP protocol version + status code + status word

HTTP protocol: http/0.9,http/1.0,http/1.1

Status code:

Status Code Description

1XX Informational Status code. The received request is being processed

2XX Success Status Code. Request normal processing complete

3XX REDIRECT Status code. Additional action required to complete the request

4XX Client Error status code. The server cannot process the request

5XX Server Error status code. Server Processing Request Error

Some important status codes:

2XX:200 204 206

3xx:301 302 303 304 307

4xx:400 401 403 404

5XX:500 503

→ Response header information

Age: Tells the client how long before the source server created the response (field units: seconds)

If the server that created the response is a cache server, the age value refers to the time value after the cached response is re-initiated for authentication to completion of authentication. The agent must add the header field, age, when creating the response.

ETag: A token that tells the client to respond to entity information, uniquely identifies the resource,

The etag is allocated by the server and there is no uniform algorithm rule.

Location: Directs the receiver to another resource

Server: Informs the client about the HTTP server application that is installed on the current server. Not only the name of the software app on the server, but also the version number and the options enabled at installation, may be included.

4, Entity header field (Request header information or field of response header information)

Content-encoding: The content encoding method of the body part of the entity

Content-language: The language used to inform the client of the principal information

Content-length: Indicates the size of the principal information (bytes)

Content-type: File (Media) type that describes the principal information

Set-cookie: Service side writes Cookie content information to client

Cookie: The client sends cookie content information to the server

Attached: The above content is referenced from the "Illustrated HTTP" book.

HTTP protocol Learning Summary

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.