据我所知,有三种类型:

不要使用GET和POST 不要使用POST而使用GET 你用哪一个都不重要。

我对这三种情况的假设正确吗?如果有,每个案例都有哪些例子?


当前回答

HTTP Post数据对数据量没有指定的限制,因为不同的浏览器对GET有不同的限制。RFC 2068声明:

服务器应谨慎 取决于URI长度大于255 字节,因为一些旧的客户端或 代理实现可能不正确 支持这些长度

具体来说,您应该根据它们的用途选择正确的HTTP结构。HTTP GET不应该有副作用,可以被HTTP代理等安全地刷新和存储。

当您想要针对url资源提交数据时,使用HTTP POST。

使用HTTP GET的一个典型示例是在搜索中,即搜索?查询=我+查询 使用HTTP POST的一个典型示例是向在线表单提交反馈。

其他回答

没有什么是你本身做不到的。关键在于您不应该修改HTTP GET上的服务器状态。HTTP代理假设由于HTTP GET不修改状态,那么用户调用HTTP GET一次还是1000次没有区别。使用这些信息,他们认为返回第一个HTTP GET的缓存版本是安全的。如果你破坏了HTTP规范,你就有破坏HTTP客户端和代理的风险。不要这样做:)

正如其他人回答的那样,get对url大小有限制,文件只能通过post提交。

我想补充的是,一个人可以添加东西到一个数据库的get和执行操作与发布。当脚本接收到post或get命令时,它可以执行作者希望它执行的任何操作。我相信缺乏理解来自于这本书选择的措辞或你的阅读方式。

脚本作者应该使用posts来更改数据库,而只使用get来检索信息。

脚本语言提供了许多访问请求的方法。例如,PHP允许使用$_REQUEST来检索post或get。应该避免使用更具体的$_GET或$_POST。

在web编程中,有更多的解释空间。一个人应该做什么,可以做什么,但哪一个更好往往是有争议的。幸运的是,在这种情况下,没有歧义。您应该使用posts来更改数据,并且应该使用get来检索信息。

第一个重要的事情是GET和POST的含义:

GET应该用来…得到……一些来自服务器的信息, 而POST应该用来向服务器发送一些信息。

在那之后,有几件事可以注意:

使用GET,用户可以在浏览器中使用“后退”按钮,并且可以将页面添加为书签 你可以作为GET传递的参数的大小是有限制的(如果我没记错的话,某些版本的Internet Explorer是2KB);POST的限制更多,通常取决于服务器的配置。

无论如何,我不认为我们可以“生活”没有GET:想想你每天在查询字符串中使用多少带有参数的url——没有GET,所有这些都不能工作;-)

来自RFC 2616:

9.3获得 GET方法意味着检索任何信息(形式为 实体)由 要求通用。如果Request-URI引用 对于数据生成过程,它是 应返回的已生成数据 作为响应中的实体而不是 进程的源文本,除非 这个文本恰好是的输出 这个过程。

9.5 POST The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions: Annotation of existing resources; Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles; Providing a block of data, such as the result of submitting a form, to a data-handling process; Extending a database through an append operation. The actual function performed by the POST method is determined by the server and is usually dependent on the Request-URI. The posted entity is subordinate to that URI in the same way that a file is subordinate to a directory containing it, a news article is subordinate to a newsgroup to which it is posted, or a record is subordinate to a database. The action performed by the POST method might not result in a resource that can be identified by a URI. In this case, either 200 (OK) or 204 (No Content) is the appropriate response status, depending on whether or not the response includes an entity that describes the result.

POST可以移动大数据,而GET不能。

但一般来说,这不是关于GET的缺点,而是一种惯例,如果你想让你的网站/web应用程序表现良好。

看看http://www.w3.org/2001/tag/doc/whenToUseGet.html