HTTP protocol Request mode: Introduction to get, post, and head in

Source: Internet
Author: User



GET: Requests the specified page information and returns the entity principal.
HEAD: Only the header of the page is requested.
POST: The requesting server accepts the specified document as a new subordinate entity for the identified URI.
PUT: Supersedes the contents of the specified document from the data that the client sends to the server.
Delete: The requested server deletes the specified page.
OPTIONS: Allow clients to view server performance.
TRACE: The request server returns the resulting content in the entity body portion of the response.
PATCH: The entity contains a table that describes the differences from the original content represented by the URI.
Move: The requesting server moves the specified page to another network address.
Copy: The request server copies the specified page to another network address.
Link: Request the server to establish a link relationship.
UNLINK: Break link relationship.
Wrapped: Allows the client to send encapsulated requests.
Extension-mothed: Additional methods can be added without altering the protocol.








HTTP defines different ways to interact with the server, and the most basic method is GET and POST. In fact GET applies to most requests, while retaining POST is only used to update the site. According to the HTTP specification, get is used for information acquisition and should be secure and idempotent. The so-called security means that the operation is used to rather than modify information. In other words, GET requests generally should not have side effects. Idempotent means that multiple requests to the same URL should return the same result. The complete definition is not as strict as it seems. Fundamentally, the goal is that when a user opens a link, she can be confident that the resource has not changed from its point of view. For example, the front page of news sites is constantly being updated. Although the second request returns a different batch of news, the operation is still considered safe and idempotent, as it always returns the current news. Vice versa. The POST request is not that easy. POST represents a request that might change resources on the server. Still take the news site as an example, the reader's comments on the article should be implemented through a POST request, because the site is different after the comment is submitted (for example, a note appears below the article);
When the form is submitted, if you do not specify method, the default is a GET request, and the data submitted in the form will be appended to the URL, separated from the URL. The alphanumeric character is sent as is, but the space is converted to the "+" sign, and the other symbol is converted to%XX, where XX is the ASCII (or ISO Latin-1) value that the symbol is represented in 16 binary. The GET request submits the data to be placed in the HTTP request protocol header, and the data submitted by the post is placed in the Entity data;
The Get method submits only 1024 bytes of data, while Post does not have this limit.

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

In the form, you can use post or get. They are all legal values of method. However, the post and get methods are at least two points different on use:
1. The Get method passes the user's input through a URL request. The Post method is in another form.
2, get mode of submission you need to use Request.QueryString to get the value of the variable, and when the post is submitted, you have to access the submitted content through Request.Form.
Study the following code carefully. You can run it to feel:

Code
<!--two form only the method property is different--
<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, then run, first test the Post method, at this time, the browser URL does not change anything, the result is returned:
The string passed through the Post method is: "Hello World"
Then the test is submitted with the Get method, note that the URL of the browser becomes:
Http://localhost/general/form/getpost.asp?Text=Hello+World
The result of the return is:
The string passed by the Get method is: "Hello World"
Finally, through the Post method submission, the browser URL is:
Http://localhost/general/form/getpost.asp?Text=Hello+World
And the returned result becomes:
The string passed by the Get method is: "Hello World"
The string passed through the Post method is: "Hello World"

Tips
Submitting data through the Get method can pose a security issue. such as a landing page. When data is submitted through the Get method, the user name and password appear on the URL. If:
1, the landing page can be cached by the browser;
2, other people can access the customer's machine.
Then someone can read the account number and password from the browser's history. Therefore, in some cases, the Get method poses a serious security problem.
Suggestions
The Post method is recommended for use in form.



If the head method is requested, the server returns only the response header, not the requested block, and the head method is common to some search engines

--------------------------------------------------------------------------------------------------------------- -----

GET: Requests the specified page information and returns the entity principal.
HEAD: Only the header of the page is requested.
POST: The requesting server accepts the specified document as a new subordinate entity for the identified URI.
PUT: Supersedes the contents of the specified document from the data that the client sends to the server.
Delete: The requested server deletes the specified page.
OPTIONS: Allow clients to view server performance.
TRACE: The request server returns the resulting content in the entity body portion of the response.
PATCH: The entity contains a table that describes the differences from the original content represented by the URI.
Move: The requesting server moves the specified page to another network address.
Copy: The request server copies the specified page to another network address.
Link: Request the server to establish a link relationship.
UNLINK: Break link relationship.
Wrapped: Allows the client to send encapsulated requests.
Extension-mothed: Additional methods can be added without altering the protocol.

Like what:
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)
Description The browser uses the Get method to request document/index.html. The browser is only allowed to receive pure ASCII code text files and HTML text files, and the engine used is mozilla/4.5 (Netscape).

When the server responds, its status line information is the version number of the HTTP, the status code, and a simple explanation of the status code. 5 Types of status codes are listed in detail now:
① Client Side Error
100 continue
101 Exchange Protocol
② success
OK
201 Created
202 Reception
203 Non-certified information
204 No Content
205 Resetting Content
206 part of the content
③ redirection
300 multi-channel selection
301 Permanent Transfer
302 Temporary transfer
303 See other
304 unmodified (not Modified)
305 using Proxies
④ Client Side Error
400 error requests (Bad request)
401 Not certified
402 Fee Required
403 Prohibition (Forbidden)
404 Not Found (not Found)
405 method does not allow
406 Not Accepted
407 Requires agent authentication
408 Request timed out
409 conflicts
410 failure
411 Required Length
412 Pieces failed
413 Request Entity too large
414 Request URI too long
415 Media type not supported
⑤ Server Error
500 Server Internal Error
501 Not implemented (not implemented)
502 Gateway Failure
504 Gateway Timeout
505 HTTP Version not supported
For example: (In the "Telnet ..." article with telnet to the 80 port, the same method used in the http/1.1, will find no display, the following supplementary explanation)
Telnet www.fudan.edu.cn 80
head/http/1.1
host:www.fudan.edu.cn/* This behavior input */
http/1.1 501 Method Not implemented
Date:web, 07:12:29 GMT/* Current date/time */
server:apache/1.3.12 (Unix)/*web Server information */
Allow:get, HEAD, OPTION, TRACE/* Supported method type */
Connection:close
connect-type:text/html; charset=iso-8859-1/* Media type of connection */

<! DOCTYPE HTML Publig "-//ietf//dtd HTML 2.0//en" >
<HTML><HEAD>
<title>501 Method
Not implemented</title>
</HEAD><BODY>
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></HTML>
The contents of the entity head can also be:
Last Modified: The time when the document was requested for most recent modification.
Expires: The time when the document was requested to expire.
Connect-length: Length of document data.
Www-authenricate: Notifies the client of the required authentication information.
Connect-encoding: Indicates if there is any use of compression technology.
Transfer-encoding: Describes the type of encoding transformation used.

With the development of the Internet, the next generation of HTTP protocol Http-ng is already brewing, it will provide better security, faster speed, the main points for improvement are: Strong modularity, high network efficiency, security and more simple structure.


HTTP protocol Request mode: Introduction to get, post, and head in


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.