The HTTP protocol that you don't know

Source: Internet
Author: User
Tags switches

HTTP protocol
1. Introduction
The HTTP protocol (Hyper text Transfer Protocol, Hypertext Transfer Protocol) is the transfer protocol used to transmit a hyper-text to a local browser from the World Wide Web (www:world Wide Web) server.
HTTP transmits data based on the TCP/IP communication protocol.
HTTP is a stateless request/response protocol based on the client/server-side (c/s) architecture model, which exchanges information through a reliable link.
2. Features
(1) HTTP is 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.
(2) HTTP is media Independent: As long as the client and the server know how to handle the data content, any type of data can be sent over HTTP. The client and server specify that the appropriate Mime-type content type be used.
(3) HTTP is stateless: 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.
2. Communication process

4. Message structure
HTTP uses a Uniform Resource identifier (Uniform Resource Identifiers, URI) to transfer data and establish a connection. Once the connection is established, the data message is routed through the format [RFC5322] and Multipurpose Internet Mail Extensions (MIME) [RFC2045] that are used by similar Internet mail.

Client Request message: Request line, request header, blank line, and request data.

1 Get/hello.txt http/1.1

2 user-agent:curl/7.16.3 libcurl/7.16.3

3 openssl/0.9.7l zlib/1.2.3

4 Host:www.example.com accept-language:en, MI

Service-side Response message: status line, message header, blank line, and response body.

1 http/1.1 OK

2 Date:mon, 12:28:53 GMT

3 Server:apache

4 last-modified:wed, 19:15:56 GMT

5 ETag: "34aa387-d-1568eb00"

6 Accept-ranges:bytes

7 content-length:51

8 vary:accept-encoding

9 Content-type:text/plain

5. Request method
The GET request specifies the page information and returns the entity principal.
HEAD is similar to a GET request, except that there is no specific content in the returned response to get the header
POST submits data to the specified resource for processing requests (such as submitting a form or uploading a file). The data is included in the request body. A POST request may result in the creation of new resources and/or modification of existing resources.
PUT replaces the contents of the specified document with the data that the client transmits to the server.
The delete request server deletes the specified page.
The Connect http/1.1 protocol is reserved for proxy servers that can change connections to pipelines.
The OPTIONS allows clients to view server performance.
TRACE echoes the requests received by the server, primarily for testing or diagnostics.
6. Status Code
HTTP status Code classification
1** information, the server receives the request and requires the requestor to continue the operation
2** successful, operation is successfully received and processed
3** Redirect, requires further action to complete the request
4** Client error, request contains syntax error or cannot complete request
5** Server error, the server has made a mistake in processing the request
HTTP Status Code list
Continue continued. The client should continue its request
101 Switching Protocols Switch protocol. The server switches the protocol based on the client's request. You can only switch to a more advanced protocol, for example, a new version of the protocol that switches to HTTP
The request was successful. Typically used for Get and post requests
201 Created has been created. A new resource was successfully requested and created
202 Accepted has been accepted. The request has been accepted, but the completion is not processed
203 Non-authoritative Information Non-authorized information. The request was successful. But the meta information returned is not on the original server, but a copy
204 no content. The server processed successfully, but the content was not returned. Make sure the browser continues to display the current document without updating the page
205 Reset content. The server processing succeeds, and the user terminal (for example: browser) should reset the document view. The browser's form fields can be cleared by this return code
206 partial content. The server successfully processed a partial GET request
Multiple Choices multiple options. The requested resource can include multiple locations, which can return a list of resource characteristics and addresses for use in the user terminal (for example: browser) selection
301 Moved Permanently permanent movement. The requested resource has been permanently moved to the new URI, the return information will include the new URI, and the browser will automatically redirect to the new URI. Any future new requests should be replaced with a new URI
302 Found Temporary movement. Similar to 301. But resources are only temporarily moved. The client should continue to use the original URI
303 See other addresses. Similar to 301. Viewing with Get and post requests
304 Not Modified has not been modified. The requested resource is not modified and no resources are returned when the server returns this status code. Clients typically cache accessed resources by providing a header indicating that the client wants to return only the resources modified after the specified date
305 Use Proxy. The requested resource must be accessed through the proxy
306 Unused has been deprecated HTTP status code
307 temporary Redirect temporary redirection. Similar to 302. REDIRECT with GET request
Bad request syntax error for client, server does not understand
401 Unauthorized Request for user authentication
402 Payment Required reserved for future use
403 Forbidden Server understands request client requests, but refuses to execute this request
404 Not the Found server could not find resources (Web pages) based on client requests. With this code, the Web designer can set up a personalized page that "the resource you requested could not be found"
405 Method not allowed in client request is forbidden
406 Not acceptable server failed to complete request based on content characteristics requested by client
407 Proxy authentication Required request proxy authentication, similar to 401, but requester should use proxy for authorization
408 Request time-out server waits for too long to be sent by the client, time-out
409 The Conflict server completes a put request from the client, it is possible to return this code, and the server handles the request when a conflict occurs
The resource requested by the 410 Gone client is no longer present. 410 is different from 404, if the resource is now permanently deleted and can use 410 code, the site designer can specify a new location for the resource through 301 code
411 Length Required Server cannot process request information sent by client without content-length
412 Precondition Failed Client request information for prerequisites error
413 Request Entity Too Large The requested entity is too large to be processed by the server, and therefore rejects it. To prevent successive requests from the client, the server may close the connection. If only the server is temporarily unable to process, it will contain a retry-after response message
414 Request-uri Too Large The requested URI is too long (URI is usually URL), the server cannot process
415 Unsupported Media Type Server is unable to process the medium format that was included with the request
416 requested range not satisfiable client requested range is not valid
417 Expectation Failed Server failed to satisfy expect request header information
Internal Server error Server internal errors, unable to complete the request
501 Not implemented server does not support the requested feature and cannot complete the request
502 Bad gateway acts as a gateway or proxy server, receiving an invalid request from the remote server
503 Service Unavailable The server is temporarily unable to process client requests due to overloading or system maintenance. The length of the delay can be included in the server's Retry-after header information
504 Gateway time-out acts as a gateway or proxy server and does not get requests from the remote server in time
505 HTTP version not supported server does not support versions of the requested HTTP protocol and cannot complete processing
Posted on 2016-07-27 15:52:06 Reply (0)
9

Ling. Avatar Ling.
A error, HTTP is stateless
b error, followed by request header
C is correct, get means get resource, post indicates a new resource, put means update resource, delete means remove resource, etc.
d Error, status code 304 means: If the client sends a conditional GET request and the request has been allowed, and the contents of the document (since the last access or according to the condition of the request) have not changed, then the server should return this status code.

The HTTP protocol that you don't know

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.