POST和GET有什么区别? [英] What is the difference between POST and GET?
问题描述
我最近才开始介入PHP / AJAX / jQuery,在我看来,这些技术的重要组成部分是 POST
和<$ c首先, POST
和之间的区别是什么? code> GET
?通过实验,我知道 GET
将返回的变量及其值添加到URL字符串中。
website.com/directory/index.php?name=YourName&bday=YourBday
但是 POST
没有。
所以,这是唯一的区别,还是有特定的规则或约定第二,我也看到了 POST
和 GET
在PHP之外:也在AJAX和jQuery中。这三个 POST
和 GET
如何不同?他们是相同的想法,相同的功能,只是有所不同?
GET 和 POST
是两种不同类型的HTTP请求。
GET / b>请求指定资源的表示。请注意,不应将GET用于导致副作用的操作,例如将其用于在Web应用程序中执行操作。其中一个原因是,GET可能被机器人或抓取工具任意使用,它们不需要考虑请求应该导致的副作用。
和
POST 提交要处理的数据(例如,从HTML表单)识别资源。数据包含在请求的正文中。这可能会导致创建新资源或更新现有资源或两者。
因此基本上 GET
用于检索远程数据, POST
用于插入/更新远程数据。
HTTP / 1.1规范(RFC 2616)第9节 方法定义 包含更多关于
GET
和 POST
以及其他HTTP方法,如果您有兴趣的话。 除了解释每种方法的预期用途之外,该规范还提供了至少一个实际的原因为什么 GET
只能用于检索数据:
使用哪些服务的作者HTTP协议不应该使用基于GET的表单来提交敏感数据,因为这会导致这些数据在Request-URI中被编码。许多现有的服务器,代理和用户代理都会将请求URI记录在第三方可能看到的某个地方。服务器可以使用基于POST的表单提交而不是
最后,使用<$ c对于AJAX请求,$ c> GET 是某些浏览器(特别是IE)会缓存
GET
请求的结果。因此,例如,如果您使用相同的 GET
请求进行轮询,即使您正在查询的数据正在服务器端进行更新,您也将始终得到相同的结果。减轻此问题的一种方法是通过附加时间戳来使每个请求的URL唯一。 I've only recently been getting involved with PHP/AJAX/jQuery and it seems to me that an important part of these technologies is that of POST
and GET
.
First, what is the difference between POST
and GET
? Through experimenting, I know that GET
appends the returning variables and their values to the URL string
website.com/directory/index.php?name=YourName&bday=YourBday
but POST
doesn't.
So, is this the only difference or are there specific rules or conventions for using one or the other?
Second, I've also seen POST
and GET
outside of PHP: also in AJAX and jQuery. How do POST
and GET
differ between these 3? Are they the same idea, same functionality, just utilized differently?
GET
and POST
are two different types of HTTP requests.
According to Wikipedia:
GET requests a representation of the specified resource. Note that GET should not be used for operations that cause side-effects, such as using it for taking actions in web applications. One reason for this is that GET may be used arbitrarily by robots or crawlers, which should not need to consider the side effects that a request should cause.
and
POST submits data to be processed (e.g., from an HTML form) to the identified resource. The data is included in the body of the request. This may result in the creation of a new resource or the updates of existing resources or both.
So essentially GET
is used to retrieve remote data, and POST
is used to insert/update remote data.
HTTP/1.1 specification (RFC 2616) section 9 Method Definitions contains more information on
GET
and POST
as well as the other HTTP methods, if you are interested.
In addition to explaining the intended uses of each method, the spec also provides at least one practical reason for why GET
should only be used to retrieve data:
Authors of services which use the HTTP protocol SHOULD NOT use GET based forms for the submission of sensitive data, because this will cause this data to be encoded in the Request-URI. Many existing servers, proxies, and user agents will log the request URI in some place where it might be visible to third parties. Servers can use POST-based form submission instead
Finally, an important consideration when using
GET
for AJAX requests is that some browsers - IE in particular - will cache the results of a GET
request. So if you, for example, poll using the same GET
request you will always get back the same results, even if the data you are querying is being updated server-side. One way to alleviate this problem is to make the URL unique for each request by appending a timestamp.
这篇关于POST和GET有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!