What are the differences between post, get, and head in HTTP? Under what conditions?

Source: Internet
Author: User
Tags domain name server
HTTP is an important protocol in the Web protocol set. It is developed from the client/server model. A client/server runs a program that communicates with each other. When a client connects to the server, it first initiates a request to the server. The server completes processing and responds to the client's request. A browser is a client program that connects to the Web server. Its port is port 80 of TCP ,. The protocol between the browser and the Web server is HTTP.
I wrote about using telnet to access HTTP/1.0 in the sixth article "using telnet to log on to non-port 23, when someone asks a question about HTTP/0.9 when using NetAnts to download a file, open ie5.0 selection tool, Internet Options, and advanced. You can find that HTTP/1.1 settings use HTTP/1.1. Therefore, I would like to give you a detailed introduction to the development history of the HTTP protocol so that you can better use HTTP to access the Internet.
The early version of HTTP is HTTP/0.9, which is applicable to simple and fast protocols for various data information, but it is far from meeting the needs of increasingly developed applications. However, HTTP/0.9 is a typical stateless HTTP protocol: each transaction is processed independently. When a transaction starts, it establishes a connection between the customer and the server, the connection is released when the transaction ends. HTTP/0.9 contains the message structure of simple-request & simple-responsed. However, the client cannot use content negotiation, so the server cannot return the media type of the entity.
In 1982, Tim Berners-Lee proposed HTTP/1.0. In the future, HTTP/1.0 becomes the most important transaction-oriented application layer protocol. This Protocol establishes and removes a connection for each request/response. It is simple and easy to manage, so it meets everyone's needs and has been widely used. The disadvantage is that the following problems still occur: slow response to user requests, severe network congestion, and security.
HTTP/1997, a commonly used protocol established in 1.1, implements the stream mode in the persistent connection operation mechanism, that is, when the client needs to send multiple requests to the same server, in fact, most web pages are composed of multiple parts (for example, multiple images). The Streamline method is used to speed up the process. The Streamline mechanism is to send multiple requests continuously and wait until these requests are sent, wait for the response. In this way, the waiting time for the response of individual requests is greatly reduced, so that we can view the response more quickly.
In addition, the HTTP/1.1 Server Processes requests in the order they are received, ensuring the correctness of transmission. Of course, when a connection is interrupted, the server automatically retransmits the request to ensure data integrity.
HTTP/1.1 also provides identity authentication, status management, cache caching, and other mechanisms. Here, I would like to mention the improvement of the cache mechanism in HTTP/1.1 on the shortcomings of HTTP/1.0. It is strictly and comprehensive, which can reduce the time delay and bandwidth. HTTP/1.1 adopts the content negotiation mechanism and selects the most appropriate content representation form.
Currently, the virtual host technology that is useful in many places can also be implemented in HTTP/1.1. The so-called virtual host technology means that the same host address actually corresponds to multiple hosts. In general, when you apply for two Homepages on one website at the same time, you can use the protocol analyzer to find that the two homepages correspond to the same IP address. In this way, using multiple identical machines to form a WWW server can increase the processing throughput.
The traditional solution is to transform the domain name server so that it can interpret the same domain name as different IP addresses based on certain algorithms. The disadvantage of corresponding to each machine of the virtual host is that each machine occupies a completely independent IP address, which is in conflict with the lack of IP addresses.
The solution provided by HTTP/1.1 includes the function of specifying different hosts in the HTTP protocol itself, so that multiple hosts can share one IP address, which improves performance and facilitates management.
Because HTTP/1.1 is a standard protocol for the Internet, the relevant syntax is described in detail here.
First, the HTTP/1.1 format can be written as follows:
The request method is to request a certain webpage program or a specific URL. The following options are available:
Get: Request the specified page information and returns the Object Body.
Head: only request the first part of the page.
Post: The request Server accepts the specified document as a new subordinate object to the identified Uri.
Put: Replace the specified document content with the data transmitted from the client to the server.
Delete: Requests the server to delete the specified page.
Options: allows the client to view the server performance.
Trace: The content returned by the request server in the response body.
Patch: an object contains a table that describes the differences between the table and the original content represented by the URI.
Move: Requests the server to move the specified page to another network address.
Copy: Requests the server to copy the specified page to another network address.
Link: Requests the server to establish a link.
Unlink: disconnected.
Wrapped: allows the client to send encapsulated requests.
Extension-mothed: You can add another method without modifying the protocol.
For example:
GET/index.html HTTP/1.1
Accept: text/plain/* plain ASCII text file */
Accept: text/html/* HTML text file */
User-Agent: Mozilla/4.5 (winnt)
The browser uses the get method to request the document/index.html. The browser can only receive plain ASCII text files and HTML text files. The engine used is Mozilla/4.5 (Netscape ).

When the server responds, the status line information is the HTTP Version Number, status code, and a brief description of the status code. Five status codes are listed in detail:
① Client Error
100 continue
101 Exchange Protocol
② Success
200 OK
201 created
202 receiving
203 non-authentication information
204 NO content
205 reset content
Part 1
③ Redirection
300 multi-Choice
301 permanent transfer
302 temporary transfer
303 see other
304 unmodified (not modified)
305 use proxy
④ Client errors
400 bad request)
401 unauthenticated
402 payment required
403 Forbidden)
404 not found)
405 method not allowed
406 not accepted
407 proxy authentication required
408 request timeout
409 conflict
410 failed
411 length required
412 condition failed
413 the Request Entity is too large
414 the request URI is too long
415 media types not supported
⑤ Server Error
500 Internal Server Error
501 not implemented (not implemented)
502 gateway failure
504 gateway timeout
505 HTTP Version Not Supported
For example, in Telnet... Use telnet to log on to port 80. If the same method is used in HTTP/1.1, no information is displayed)
Telnet www.fudan.edu.cn 80
Headers/HTTP/1.1
HOST: www.fudan.edu.cn/* content entered in this behavior */
HTTP/1.1 501 method not implemented
Date: Web, 01 Nov 2000 07:12:29 GMT/* Current date/time */
Server: Apache/1.3.12 (UNIX)/* Web server information */
Allow: Get, Head, option, trace/* supported method types */
Connection: Close
Connect-type: text/html; charset = iso-8859-1/* connected media type */

<! Doctype HTML publig "-// IETF // dtd html 2.0 // en">
<HTML> <Title> 501 Method
Not implemented </title>
</Head> <body>
<H1> method not implemented Head to/inde
X.html not supported. <p>
Invalid method in request head/HTP/1.1 <p>
<HR>
<Address>
Apache/1.3.12 server at www.fudan.edu.cn port 80 </address>
</Body> The content of the object header can also be:
Last modified: The latest modification time of the Request Document.
Expires: The expiration time of the Request Document.
Connect-length: the length of the document data.
WWW-authenricate: indicates the authentication information required by the client.
Connect-encoding: whether compression technology is used.
Transfer-encoding: Specifies the encoding conversion type.

With the development of the Internet, the next generation of HTTP protocol HTTP-ng has been brewing, it will provide better security, faster speed, its improvement points are: strong modularity, high network efficiency, better security, and simpler structure.
 

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.