据我所知,有三种类型:

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

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


当前回答

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

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

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

其他回答

Gorgapor, mod_rewrite仍然经常使用GET。它只是允许将一个更友好的URL转换为一个带有GET查询字符串的URL。

短的版本

GET:通常用于已提交的搜索请求,或者任何您希望用户能够再次调出确切页面的请求。

GET的优点:

url可以安全地添加书签。 页面可以安全地重新加载。

GET的缺点:

变量作为名称-值对通过url传递。(安全风险) 可以传递的变量数量有限。(基于浏览器。例如,Internet Explorer被限制为2048个字符。)

POST:用于更高安全性的请求,其中数据可能用于更改数据库,或者您不希望别人添加书签的页面。

POST的优点:

url中不显示名称-值对。(安全+= 1) 可以通过POST传递无限数量的名称-值对。参考。

POST的缺点:

使用POST数据的页面不能被书签。(如果你愿意的话。)

完整版

直接来自超文本传输协议——HTTP/1.1:

9.3 GET The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process. The semantics of the GET method change to a "conditional GET" if the request message includes an If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match, or If-Range header field. A conditional GET method requests that the entity be transferred only under the circumstances described by the conditional header field(s). The conditional GET method is intended to reduce unnecessary network usage by allowing cached entities to be refreshed without requiring multiple requests or transferring data already held by the client. The semantics of the GET method change to a "partial GET" if the request message includes a Range header field. A partial GET requests that only part of the entity be transferred, as described in section 14.35. The partial GET method is intended to reduce unnecessary network usage by allowing partially-retrieved entities to be completed without transferring data already held by the client. The response to a GET request is cacheable if and only if it meets the requirements for HTTP caching described in section 13. See section 15.1.3 for security considerations when used for forms. 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.

我不认为使用get有什么问题,我用它来做一些简单的事情,在查询字符串上保留东西是有意义的。

使用它来更新状态-像delete.php的GET ?Id =5删除一个页面是非常危险的。人们发现,当谷歌的网络加速器开始在页面上预取url时,它会击中所有的“删除”链接,并清除人们的数据。同样的事情也会发生在搜索引擎蜘蛛身上。

这就涉及到REST的概念以及web是如何被使用的。在软件工程电台上有一个很好的播客,对Get和Post的使用进行了深入的讨论。

Get用于从不需要更新操作的服务器中提取数据。其思想是,您应该能够反复使用相同的GET请求并返回相同的信息。URL在查询字符串中有get信息,因为它意味着能够轻松地发送到其他系统,人们喜欢在哪里找到一些东西的地址。

Post应该被用于(至少在web基于的REST架构中)将信息推送到服务器/告诉服务器执行一个操作。例如:更新此数据,创建此记录。

来自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.