HTTP request methods: Get, post, and head

Source: Internet
Author: User
Http get, post, and head descriptions
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.


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.



HTTP defines different methods for interaction with the server. The most basic methods are get and post. In fact, get applies to most requests, while retaining post is only used to update sites. According to the HTTP specification, get is used to  and should be secure and idempotent. The so-called security means that this operation is used to instead of modifying information. In other words, get requests generally do not have side effects. Idempotence means that multiple requests to the same URL should return the same result. The complete definition is not as strict as it looks. Basically, the goal is that when a user opens a link, she can be confident that the resource has not changed from her own perspective. For example, the front pages of news sites are constantly updated. Although the second request will return a different batch of news, this operation is still considered safe and idempotent because it always returns the current news. And vice versa. POST requests are not that easy. Post indicates a request that may change resources on the server. Taking the news site as an example, the reader's comments to the article should be implemented through the POST request, because the site is already different after the annotation is submitted (for example, an annotation appears below the article );
If no method is specified during form submission, the default value is get. The data submitted in form will be appended to the URL? Separated from the URL. The letter and number characters are sent as they are, but spaces are converted to "+". Other symbols are converted to % xx, XX represents the ASCII (or ISO Latin-1) value in hexadecimal notation. The data submitted for the GET request is placed in the HTTP Request Header, while the data submitted for the post is placed in the object data;
Data submitted in get mode can contain a maximum of 1024 bytes, whereas post mode does not.


What is the difference between using "Post" and "get" in a form?

In form, you can use post or get. They are all valid values of method. However, the post and get methods are at least two different in use:
1. The get method transmits user input through URL requests. The post method is in another form.
2. You need to use request. querystring to obtain the value of the variable for get-based submission. When using post-based submission, you must use request. Form to access the submitted content.

Study the following code carefully. You can run it to feel it:

Code
<! -- Two forms have different method Attributes -->
<Form action = "getpost. asp" method = "get">
<Input type = "text" name = "text" value = "Hello World"> </input>
<Input type = "Submit" value = "method = get"> </input>
</Form>
<Br>
<Form action = "getpost. asp" method = "Post">
<Input type = "text" name = "text" value = "Hello World"> </input>
<Input type = "Submit" value = "method = post"> </input>
</Form>

<Br>
<Br>

<% If request. querystring ("text") <> "" Then %>
The string passed through the get method is: "<B> <% = request. querystring (" text ") %> </B>" <br>
<% End if %>

<% If request. Form ("text") <> "" Then %>
The string passed through the POST method is: "<B> <% = request. Form (" text ") %> </B>" <br>
<% End if %>

Description
Save the above Code as getpost. asp and run it. First test the POST method. At this time, the URL of the browser does not change, and the returned result is:
The string passed through the POST method is: "Hello World"
Then test the submission using the get method. Note that the URL of the browser is changed:
Http: // localhost/General/form/getpost. asp? TEXT = Hello + world
The returned result is:
The string passed through the get method is: "Hello World"
Finally, submit the file through the POST method. The URL of the browser is:
Http: // localhost/General/form/getpost. asp? TEXT = Hello + world
The returned result is:
The string passed through the get method is: "Hello World"
The string passed through the POST method is: "Hello World"

Prompt
Submitting data through the get method may cause security issues. For example, a login page. When you submit data using the get method, the user name and password will appear on the URL. If:
1. the login page can be cached by the browser;
2. Others can access the customer's machine.
Then, others can read the customer's account and password from the browser's history. Therefore, in some cases, the get method may cause serious security problems.
Suggestions
In form, the POST method is recommended.

 

If the head method is used for a request, the server returns only the response title, instead of the requested document. The head method is generally used by some search engines.

Bytes --------------------------------------------------------------------------------------------------------------------

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.