HTTP protocol--Brief analysis

Source: Internet
Author: User
Tags response code url example

The http--Hypertext Transfer Protocol (hypertext Transfer Protocol) is the most widely used network protocol on the Internet and is the standard that all WWW files must comply with.

To be a good web developer, you must be familiar with the HTTP protocol, today, to share your understanding of the HTTP protocol. Welcome everyone to communicate correct.

The HTTP protocol is an object-oriented, stateless, non-connected protocol that is based on the TCP protocol, which belongs to the application layer.

It is simple and fast, when the customer requests the service to the server, only needs to transfer the request method and the path. The requested method has a POST,, put, and so on.

Attention:

The so-called stateless protocol, does not mean that HTTP is not based on TCP connections using the UDP protocol, but that the processing of things do not have a memory function, the server does not know the state of the client, the same server open a different Web page is no connection between.
And our common implementation of the login status of the website, shopping cart and so on, is the use of cookies and session implementation, through the cookie and session memory client state.

The meaning of the so-called 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.

The process of the HTTP request:

It can be roughly divided into seven steps:


1. Establish a TCP connection (locate the target host based on the URL entered in the browser to establish a connection)

2. The client browser sends a request command to the server

3. client browser sends request header information

4. Server resolution request message to answer

5. The server sends the answer header information

6. The server sends data to the browser

7. The server shuts down the TCP connection

URL section:

URL Example: http://localhost:8080/Student/login.jsp

/HTTP Hostname: Port number/resource address

HTTP means to locate network resources through the HTTP protocol, the host represents a legitimate Internet host domain name, the following number represents the port number, default is 80, and the port number is followed by the path of the requested resource

HTTP message:

Our common composition of HTTP request messages consists of the request part and the response part.

Request section:

The request section consists of three parts: the request line, the message header, and the request body.

1. Request Line composition: Client request mode/Request Resource/http version number

2. The common request headers are as follows:

Accept: Used to tell the server what type of data the client supports
Accept-charset: The encoding used to tell the server that the client is using
Accept-encoding: Used to tell the server, the compression format of the data
Accept-language: The language environment of the client
Host: Tell the server what hostname you want to access
If-modified-since: Tells the server the cache time of the resource
Referer: The client through this tells the server, from which resources to visit the server
User-agent: Client's software Environment declaration

Response section:

The HTTP response is also made up of three parts, namely: status line, response header, response body

1. Status line composition: version of Server HTTP protocol/Response status code sent back by server/text description of status code

Status code part of the status line:

200-299 successfully completed processing
300-399 further refinement requests
400-499 Client Request Error
500-599 Server-side error

Common Status Codes:

200 (success) The server has successfully processed the request. Typically, this indicates that the server provided the requested Web page.
201 (created) The request was successful and the server created a new resource.
202 (accepted) the server has accepted the request but has not yet processed it.
203 (non-authoritative information) the server has successfully processed the request, but the information returned may be from another source.
204 (no content) the server successfully processed the request, but did not return any content.
205 (reset content) the server successfully processed the request, but did not return any content.
206 (partial) The server successfully processed a partial GET request.
300 (multiple options) for requests, the server can perform a variety of operations. The server can select an action based on the requestor (user agent) or provide a list of actions for the requestor to select.
301 (permanently moved) The requested page has been permanently moved to a new location. When the server returns this response (a response to a GET or HEAD request), the requestor is automatically forwarded to the new location.
302 (Temporary move) The server is currently responding to requests from a Web page in a different location, but the requestor should continue to use the original location for future requests.
303 (View other locations) The server returns this code when the requestor should use a separate GET request for the different locations to retrieve the response.
304 (not modified) The requested webpage has not been modified since the last request. When the server returns this response, the Web page content is not returned.
305 (using a proxy) the requestor can only use the proxy to access the requested Web page. If the server returns this response, it also indicates that the requestor should use the proxy.
307 (Temporary redirect) The server is currently responding to requests from a Web page in a different location, but the requestor should continue to use the original location for future requests.
400 (Error request) The server does not understand the syntax of the request.
401 (unauthorized) request authentication is required. The server may return this response for pages that need to log on.
403 (Forbidden) The server rejects the request.
404 (not found) The requested Web page was not found by the server.
405 (method Disabled) Disables the method specified in the request.
406 (not accepted) cannot use the requested content attribute to respond to the requested Web page.
407 (requires proxy authorization) This status code is similar to 401 (unauthorized), but specifies that the requestor should authorize the use of the proxy.
408 (Request timed out) A timeout occurred while the server was waiting for a request.
409 (conflict) The server has a conflict when it finishes the request. The server must include information about the conflict in the response.
410 (Deleted) If the requested resource has been permanently deleted, the server returns this response.
411 (requires valid length) The server does not accept requests that do not contain a valid Content-Length header field.
412 (precondition not met) the server does not meet one of the prerequisites set by the requestor in the request.
413 (Request entity too Large) The server cannot process the request because the request entity is too large to exceed the processing power of the server.
414 (The requested URI is too long) The requested URI (usually the URL) is too long for the server to process.
415 (Unsupported media type) The requested format is not supported by the requested page.
416 (The request scope does not meet the requirements) if the page cannot provide the requested scope, the server returns this status code.
417 (unmet expectations) the server does not meet the requirements for the expected Request header field.
500 (server internal error) the server encountered an error and could not complete the request.
501 (not yet implemented) the server does not have the capability to complete the request. For example, this code may be returned when the server does not recognize the request method.
502 (Error Gateway) The server receives an invalid response from the upstream server as a gateway or proxy.
503 (Service Unavailable) the server is not currently available (due to overloading or downtime maintenance). Typically, this is only a temporary state.
504 (Gateway Timeout) The server acts as a gateway or proxy, but does not receive requests from the upstream server in a timely manner.
505 (HTTP version not supported) the HTTP protocol version used in the request is not supported by the server.

2. The common message header is as follows:

Location: With 302 yards, do request redirection
Server: This tells the type of client server through this
Content-encoding: Data compression format
Content-length: Length of loopback data
Content-type: Types of loopback data
Last-modified: Cache time for the current resource
Refresh: How often
Content-disposition: The server opens by telling the browser how to download
Transfer-encoding: Cached format for browser data
Expires: How long to cache the loopback resource

3. The response body is the content of the resources returned by the server

Postscript:

We currently use the HTTP protocol is 1.1 version

Some of the differences between versions 1.1 and 1.0 are listed below

About links (Request header Connection:keep-alive):

In version 1.1, all connections are persisted by default, unless the request header or response header indicates that you want to close, when a resource on the server is requested, a TCP connection for transmitting HTTP data is not closed for a period of time, and if the client still needs to continue to request data, it will continue to use this established connection.

About the status response code:

Status Response code: Only 16 status response codes are defined in http/1.0, which is not specific enough for error reporting. 24 new status response codes have been added to the HTTP1.1 version.

About the Host header field:

In HTTP1.0, each server is considered to be bound to a unique IP customization, so the URL does not pass the hostname, but with the technology and development of the virtual host, the Hsot header domain is supported in a HTTP1.1 request message and Response message, if no Host header field in the request message will report a 400 error

HTTP protocol--Brief analysis

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.