What's the difference when using GET
or POST
method? Which one is more secure? What are (dis)advantages of each of them?
相关问题
- Angular RxJS mergeMap types
- Laravel Option Select - Default Issue
- HTML form is not sending $_POST values
- How to use Control.FromHandle?
- Google Apps Script: testing doPost() with cURL
相关文章
- C#使用http访问网络,有办法用指定网卡访问网络嘛?
- C#中 public virtual string Category { get; }这么写会报错:
- 请大神帮忙 post向https接口发送数据 部署到服务器为什么运行一会后就会报空指针
- WCF发布Windows服务 POST方式报错 GET方式没有问题 应该怎么解决?
- 用 $.ajax POST 请求数据报错
- 设备发送一个http post请求,接收不到
- Is a unicode user agent legal inside an HTTP heade
- Show a different value from an input that what wil
It's not a matter of security. The HTTP protocol defines GET-type requests as being idempotent, while POSTs may have side effects. In plain English, that means that GET is used for viewing something, without changing it, while POST is used for changing something. For example, a search page should use GET, while a form that changes your password should use POST.
Also, note that PHP confuses the concepts a bit. A POST request gets input from the query string and through the request body. A GET request just gets input from the query string. So a POST request is a superset of a GET request; you can use
$_GET
in a POST request, and it may even make sense to have parameters with the same name in$_POST
and$_GET
that mean different things.For example, let's say you have a form for editing an article. The article-id may be in the query string (and, so, available through
$_GET['id']
), but let's say that you want to change the article-id. The new id may then be present in the request body ($_POST['id']
). OK, perhaps that's not the best example, but I hope it illustrates the difference between the two.I use GET when I'm retrieving information from a URL and POST when I'm sending information to a URL.
The best answer was the first one.
You are using:
GET
andPOST
are HTTP methods which can achieve similar goalsGET
is basically for just getting (retrieving) data, AGET
should not have a body, so aside from cookies, the only place to pass info is in the URL and URLs are limited in length ,GET
is less secure compared toPOST
because data sent is part of the URLNever use
GET
when sending passwords, credit card or other sensitive information!, Data is visible to everyone in the URL, Can be cached data .GET
is harmless when we are reloading or calling back button, it will be book marked, parameters remain in browser history, only ASCII characters allowed.POST
may involve anything, like storing or updating data, or ordering a product, or sending e-mail.POST
method has a body.POST
method is secured for passing sensitive and confidential information to server it will not visible in query parameters in URL and parameters are not saved in browser history. There are no restrictions on data length. When we are reloading the browser should alert the user that the data are about to be re-submitted.POST
method cannot be bookmarkedThe reason for using POST when making changes to data:
Also, don't put sensitive information in the query string (only option with GET) because it shows up in the address bar, bookmarks and server logs.
Hopefully this explains why people say POST is 'secure'. If you are transmitting sensitive data you must use SSL.
When the user enters information in a form and clicks Submit , there are two ways the information can be sent from the browser to the server: in the URL, or within the body of the HTTP request.
The GET method, which was used in the example earlier, appends name/value pairs to the URL. Unfortunately, the length of a URL is limited, so this method only works if there are only a few parameters. The URL could be truncated if the form uses a large number of parameters, or if the parameters contain large amounts of data. Also, parameters passed on the URL are visible in the address field of the browser not the best place for a password to be displayed.
The alternative to the GET method is the POST method. This method packages the name/value pairs inside the body of the HTTP request, which makes for a cleaner URL and imposes no size limitations on the forms output. It is also more secure.