When to use GET? When to use POST?

Source: Internet
Author: User
Tags php and mysql web database

Both GET and POST Methods send data to the server, but which one should you use?

The HTTP standard includes these two methods for different purposes. POST is used to create resources. The content of resources is included in the HTTP request content. For example, processing the order form and adding new data rows to the database.

When the request has no side effects (such as search), you can use the GET method. When the request has side effects (such as adding data rows), you can use the POST method. A more practical problem is that the GET method may produce a long URL, which may exceed the URL length limit of Some browsers and servers.

If any of the following conditions is met, the POST method is used:

* The request results have continuous side effects, such as adding new data rows to the database.
* If the GET method is used, the data collected on the form may make the URL too long.
* The data to be transmitted is not encoded in 7-bit ASCII format.

If any of the following conditions is met, use the GET method:

* The request is for searching resources. HTML form data is only used for searching.
* The request results have no sustained side effects.
* The total length of collected data and input field names in HTML forms cannot exceed 1024 characters.

The above content is taken from the Book Web Database Application with PHP and MySQL, 2nd Edition, Chinese version of PHP & MySQL Web Database Application Development Guide. The original English text is as follows:

GET versus POST

Both the GET and POST methods send data to the server, but which method shocould you use?

The HTTP standard des the two methods to achieve different goals. the POST method was intended to create a resource. the contents of the resource wocould be encoded into the body of the HTTP request. for example, an order form might be processed and a new
Row in a database created.

The GET method is used when a request has no side effects (such as sort Ming a search) and the POST method is used when a request has side effects (such as adding a new row to a database ). A more practical issue is that the GET method may result in long URLs,
And may even exceed some browser and server limits on URL length.

Use the POST method if any of the following are true:

* The result of the request has persistent side effects such as adding a new database row.
* The data collected on the form is likely to result in a long URL if you used the GET method.
* The data to be sent is in any encoding other than seven-bit ASCII.

Use the get method if all the following are true:

* The request is to find a resource, and HTML form data is used to help that search.
* The result of the request has no persistent side effects.
* The data collected and the input field names in a HTML form are in total less than 1,024 characters in size.

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.