When To Use Http Post Or Get Methods In Html Forms
Overview
HTTP request methods are defined in RFC2616 Section 9 Method Definitions. These methods are also known as verbs as they indicate the desired action to be performed on an identified resource.
Understanding the basics in simple terms
From a practical point of view, these are the most simple (not so accurate) definitions and differences.
GET method
$_GET is an array of variables passed to the current script via the URL parameters.
/data/form?name1=value1&name2=value2
POST method
$_POST is an array of variables passed to the current script via the HTTP POST method.
POST /data/form HTTP/1.1
Host: example.com
name1=value1&name2=value2
When to use GET vs POST methods
In most cases:
GET should be used to __retrieve data__ from a specified resource and
sending __non-sensitive__ data.
POST is the preferred way for sending __form data__.
GET | POST | |
---|---|---|
Can be __cached__ | ||
Remain in the __browser history__ | ||
Can be __bookmarked__ | ||
Data visible in URL | ||
Used with __sensitive data__ | ||
__Data length__ restrictions | ||
ASCII data type allowed | ||
Binary data type allowed | ||
Content-Type application/x-www-form-urlencoded | ||
Content-Type multipart/form-data |
A search page should use GET, while a form that changes your password should use POST.
References
- When should I use GET or POST method? What’s the difference between them?
- HTTP Methods: GET vs. POST
- Methods GET and POST in HTML forms - what’s the difference?
comments powered by Disqus
- When To Use Http Post Or Get Methods In Html Forms
Articles
Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 . Terms and Policy.
Powered by SimpleIT Hugo Theme
·