HTTP protocol Learning Notes (i) Request method name and status code

Source: Internet
Author: User
Tags current time error status code http request port number

The HTTP protocol is an application-layer protocol on top of the TCP protocol and is a protocol for communication between application processes. It is called the application layer protocol because it does not have to care about how the data arrives at the peer, what goes through before it arrives at the other party's application, but only the data format that is used to negotiate, so that one party can resolve the other party's intentions.

This is also the real purpose of the TCP/IP protocol, without undue care for the underlying implementation details

When the user entered a Web site in the browser, mainly through the following stages of DNS resolution, the host name to find the host IP address to the corresponding IP address and port (the default is 80) Send connection request, the server receives the request (three times handshake) the browser sends the HTTP request Packet Segment server to resolve the HTTP request, Generate response message Segment Browser resolves HTTP response, displays resource information on screen to remain connected or disconnected, depending on whether keep-alive is turned on

You can refer to this blog for more details from the input URL to the page load what happened to the URL format

Whether or not to learn the HTTP protocol, always listen to the URL of this thing, usually entered in the browser URL, nature is the URL of the Buddha. But what about URIs?

The URI is called the Uniform Resource Identifier, and it has two forms, namely, url and urn

URL, a Uniform Resource locator is the most common form of a URI that describes a resource's specific location on a particular server. For example, when you enter the following URL

Http://www.balabala.com/index.html

The actual resource to be accessed is the index.html file under the current directory of the target host server, and

Http://www.balabala.com/image/hello.jpg

To access the Hello.jpg file under the image subdirectory under the current directory of the target host server

URLs allow you to pinpoint exactly where a resource is located. But if the internal directory of the server host changes, then the site will change

The full format of the URL is as follows

Although very complex, but basically no URL contains so complete, because the HTTP default port number is 80, often omitted, so usually use protocol, address, path three parts is enough to locate a host of some resources, such as the following URL

Http://www.balabala.com/index.html

Where HTTP is the protocol used, www.balabala.com represents the target server's host IP or hostname,/index.html represents the target host's resource path

In addition to the above three parts, there are more occurrences of the query string, which starts with the ID, usually the variable value that appears later as a parameter to the accessed resource (dynamic Resource). such as the following URL

http://www.balabala.com/cgi-bin/adder?a=1&b=2

First, it intercepts the resource location/cgi-bin/adder (this assumes that adder is an executable file that receives two numbers, returns addition, and)

and 1 and 2 as parameters call/cig-bin/adder this program, and then return the results of the calculation to the client

A urn, known as a Uniform Resource name, is a form of locating resources by file names and is currently being researched ... HTTP Request message Segment

The communication between the client and the server is based on the HTTP protocol, and the data format sent by both parties must conform to the HTTP protocol standard so that the receiver can resolve the intent of the sending party.

The HTTP protocol requires that the client send the request first, and then the server sends a response after processing. The server cannot proactively send data to the client without receiving a client request.

WebSocket was born to solve this problem, such as a Web server to get time, a connection will be the current time to actively send to the client

The request message segment is divided into three parts: request line, request header, request body (data entity). The request line consists of the method name, the resource path, and the version number three parts

Get/index.html http/1.1
Method Name

The method name indicates the client's intent, several commonly used methods named Get, POST, HEAD, PUT, OPTIONS, trace, etc. get

Get is the most common method used when a client wants to get the contents of a resource from a server. The server returns the resource content as the data entity of the response message segment

HEAD

The head method is similar to get, but the server only returns information about the resource (such as file size, type, etc.) through the HTTP response header, and the data entity of the response message segment is empty

PUT

The Put method indicates that the client wants to generate a file on the server, the file name is indicated by the resource path of the request line, and the contents are indicated by the data entity. If a file with the same name exists on the server, overwrite

POST

The Post method means that the client intends to submit some data to the server, such as the librarian wants to add new books to the server's database, and can submit a form by post, including various information about the book

TRACE

The trace method indicates that the client wants to see what it is like to send the request segment itself, that is, the data entity part of the HTTP response header that the server replied to is the request segment it received. Because the proxy server may be in the process of sending the HTTP request message segment to the server, and the proxy server may change the request segment, the client can use the trace method to explore

OPTIONS

The options method is used to obtain all the method names supported by the server to prevent clients from using methods that are not supported by the server

DELETE

The Delete method is used to delete a resource on the server and whether it is deleted depends on the server

HTTP Response message segment

The HTTP response message segment consists of a response line, a response header, and a response body (data entity). When the server finishes processing the client's request, it sends a response message segment to the client informing the server of the processing results.

For example, the client wants to get the content of the target resource/index.html, if the server locates the index.html file correctly, it will return its contents as the data entity to the client. However, if the server does not find the/index.html file or does not recognize the HTTP request information, it will return a response message segment that represents the error.

The response line contains the HTTP protocol version number, status code, and status information

http/1.1 OK
Status Code

Status codes are used to describe the server's handling of client requests, divided into five categories, ranging from 100 to 599 total 600 100~199 representing informational status codes

Use less 200~299 to represent success status codes

These status codes indicate that the client's request server has been successfully processed. Common status codes and explanations are as follows

300~399 on behalf of the redirect status code

These status codes tell the client to either use the alternate location to access the desired resource, or what the server can return to replace the resource content

For example, the client requests a resource information on the server, but the resource is moved elsewhere, and the server returns the new location of the resource to the client, and then the client requests the resource information again.

The common status codes are

400~499 on behalf of client error status code

For example, the most annoying 404, which indicates that the server is ignorant of the resources requested by the client

The common status codes are as follows

500~599 represents server error status

Indicates a server error, common status codes are as follows

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.