Http protocol learning summary, http Protocol Summary

Source: Internet
Author: User
Tags error status code http authentication

Http protocol learning summary, http Protocol Summary

This article is a summary of the basic knowledge of Http over the past few days. The content includes the principles of the Http protocol, Http request information, Http response information, and Http protocol status code.

1. Basic principles of Http: A client sends a request to the server. The server processes the request and processes the request accordingly. As shown in.

Figure 1 Http protocol schematic

 

The following is a simple sample code for request and response:

 

Client request:

GET/HTTP/1.1 Host: localhostAccept: text/htmlAccept-Language: en-usAccept-Encoding: gzip, deflateConnection: keep-alive empty line (CR + LF)

 

Server Response:

HTTP/1.1 200 OK Date: Fri, 13 Jul 2012 02:45:30 GMTServer: ApacheLast-Modified: Fri, 31 Agu 2007 02:02:20 GMTETag: "45bae1-16a-46d776ac" Connection: closeContent-Type: text/htmlContent-Length: 362 empty rows (CR + LF) 

 

2. Http request

A. Request Message format:

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

Request Line↔GET, HTTP, 1.1

Request Header Information↔Host: localhost

...

...

...

Empty row (CR + LF)

[Request subject information] (optional)

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

B. Description:

→ Request line: Request Method + Request Path + Http Protocol version

Request Methods: 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: name of the requested Host (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,

Host is required to specify the Host under this IP address.

Accept: the type of files that can be processed by the client. (Text/html, text/plain, image/jpeg)

Accept-Encoding: Content Encoding and priority sequence supported by the user agent (gzip, deflate, compress)

Accept-Charset: Character Set and priority order (iso-8859-5) supported by the user agent)

Referer: indicates the URI of the original resource requested by the server (This field can be used for anti-leech protection)

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

User-Agent: transmits the browser and User Agent Name of the Creation request.

 

3. Http response

A. Response Message format

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

Response line↔HTTP/1.1 200 OK

Response Header Information↔Server: Apache

...

...

...

Empty row (CR + LF)

[Response body information] (optional)

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

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 information status code. The received request is being processed.

2XX success status code. Request processed

3XX redirection status code. Additional operations are required to complete the request

4XX client error status code. The server cannot process the request.

5XX server error status code. An error occurred while processing the request on the server.

Some important status codes:

2XX: 200 204 206

200 (OK) → client requests are processed properly on the server

204 (No Content) → the server successfully processes the received request, but the body section of the entity is not included in the Response Message.

206 (Partial Content) → the client executes the range request, and the server successfully executes the GET request

 

3XX: 301 302 303 304

301 (Moved Permanently) → permanent redirection. Indicates that the requested resource has been assigned a new URI. In the future, use the URI currently referred to by the Resource

302 (Found) → temporary redirection. Indicates that the requested resource has been assigned a new URI. You are expected to use the new URI to access the resource.

303 (See Other) → indicates that the requested resource should be obtained using the GET method because the requested resource has another URI.

304 (Not Modified) → indicates that when the client sends a conditional request, the server allows the request to access the resource, but does Not meet the conditions.

304 when the status code is returned, it does not contain any body part of the response

307 (Temporary Redirect) → Temporary redirection. It has the same meaning as 302, but 302 will convert POST to GET, while 307 will not convert POST to GET

 

4XX: 400 401 403 404

400 (Bad Request) → indicates a syntax error in the Request Message

401 (Unauthorized) → indicates that the sent request must pass the HTTP authentication information. If a request has been made before, this indicates that the user authentication fails.

403 (Forbidden) → indicates that access to the requested resource is rejected by the server

404 (Not Found) → the table name cannot find the requested resource on the server

 

5XX: 500 503

500 (Internal Server Error) → indicates an Error occurred when the Server executes the request. There may also be bugs or some temporary faults in Web applications.

503 (Service Unavailable) → indicates that the server is temporarily overloaded or is being shut down for maintenance, and the request cannot be executed now

 

→ Response header information

Age: indicates how long ago the client source server created a response (in seconds)

If the server to which the response is created is a cache server, the Age value indicates the time when the cached response initiates another authentication and completes the authentication.

The header field Age must be added when the proxy is created.

ETag: indicates the tag that notifies the client to respond to entity information and uniquely identifies the resource,

ETag is allocated by the server and there are no unified algorithm rules.

Location: directs the recipient to the Location where another resource is located.

Server: inform the client of the information about the HTTP Server application installed on the current Server. Not only the software application name on the server is marked,

It may also include the version number and options enabled during installation.

 

 4. object header fields (request header or response header fields)

Content-Encoding: Content Encoding Method Used for the entity's Subject

Content-Language: Language used to inform the client of the Subject Information

Content-Length: The size (in bytes) of the subject information)

Content-Type: Specifies the file (media) Type of the subject information.

Set-Cookie: the server writes Cookie content information to the client.

Cookie: the client sends the Cookie content to the server.

 

 

 

Appendix: For the above content, see illustration HTTP.

 

 

 

 

Related Article

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.