你什么时候使用POST,什么时候使用GET? [英] When do you use POST and when do you use GET?
问题描述
根据我的收集,有三类:
From what I can gather, there are three categories:
- 绝不使用
GET
并使用POST
- 切勿使用
POST
并使用GET
- 使用哪一个并不重要。
- Never use
GET
and usePOST
- Never use
POST
and useGET
- It doesn't matter which one you use.
我假设这三个案件是否正确?如果是这样,每个案例的一些例子是什么?
Am I correct in assuming those three cases? If so, what are some examples from each case?
推荐答案
使用 POST
对于破坏性操作,例如创建(我知道讽刺),编辑和删除,因为你无法在你的地址栏中点击 POST
操作浏览器。如果允许某人调用某个操作是安全的,请使用 GET
。所以这样的网址如下:
Use POST
for destructive actions such as creation (I'm aware of the irony), editing, and deletion, because you can't hit a POST
action in the address bar of your browser. Use GET
when it's safe to allow a person to call an action. So a URL like:
http://myblog.org/admin/posts/delete/357
应该带您进入确认页面,而不是简单地删除该项目。以这种方式避免事故要容易得多。
Should bring you to a confirmation page, rather than simply deleting the item. It's far easier to avoid accidents this way.
POST
也比更安全> GET
,因为您没有将信息粘贴到URL中。因此,对于收集密码或其他敏感信息的HTML表单,使用 GET
作为方法
并不是最好的主意。
POST
is also more secure than GET
, because you aren't sticking information into a URL. And so using GET
as the method
for an HTML form that collects a password or other sensitive information is not the best idea.
最后一点: POST
可以传输比 GET <更多的信息/ code>。 'POST'对传输的数据没有大小限制,而'GET'限制为2048个字符。
One final note: POST
can transmit a larger amount of information than GET
. 'POST' has no size restrictions for transmitted data, whilst 'GET' is limited to 2048 characters.
这篇关于你什么时候使用POST,什么时候使用GET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!