据我所知,有三种类型:
不要使用GET和POST 不要使用POST而使用GET 你用哪一个都不重要。
我对这三种情况的假设正确吗?如果有,每个案例都有哪些例子?
据我所知,有三种类型:
不要使用GET和POST 不要使用POST而使用GET 你用哪一个都不重要。
我对这三种情况的假设正确吗?如果有,每个案例都有哪些例子?
当前回答
我的一般经验法则是,当您向服务器发出不打算改变状态的请求时使用Get。post是为更改状态的服务器请求保留的。
其他回答
从w3schools.com:
What is HTTP? The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers. HTTP works as a request-response protocol between a client and server. A web browser may be the client, and an application on a computer that hosts a web site may be the server. Example: A client (browser) submits an HTTP request to the server; then the server returns a response to the client. The response contains status information about the request and may also contain the requested content. Two HTTP Request Methods: GET and POST Two commonly used methods for a request-response between a client and server are: GET and POST. GET – Requests data from a specified resource POST – Submits data to be processed to a specified resource
在这里我们区分主要的区别:
POST可以移动大数据,而GET不能。
但一般来说,这不是关于GET的缺点,而是一种惯例,如果你想让你的网站/web应用程序表现良好。
看看http://www.w3.org/2001/tag/doc/whenToUseGet.html
1.3 HTTP GET / POST选择快速检查
在以下情况下使用GET:
The interaction is more like a question (i.e., it is a safe operation such as a query, read operation, or lookup).
在以下情况下使用POST:
The interaction is more like an order, or
The interaction changes the state of the resource in a way that the user would perceive (e.g., a subscription to a service), or
The user be held accountable for the results of the interaction.
源。
因为get是纯粹的url,它们可以被web浏览器缓存,并且可能更好地用于一致生成的图像之类的事情。(设置过期时间)
一个来自gravatar页面的例子:http://www.gravatar.com/avatar/4c3be63a4c2f539b013787725dfce802?d=monsterid
GET可能会产生稍微更好的性能,一些web服务器在调用处理程序之前将POST内容写入临时文件。
另一件需要考虑的事情是尺寸限制。get的上限是URL的大小,标准是1024字节,不过浏览器可能支持更多。
传输更多的数据应该使用POST来获得更好的浏览器兼容性。
即使小于这个限制也是一个问题,正如另一个帖子所写的,URL中的任何内容都可能最终出现在浏览器UI的其他部分,比如历史记录。
Gorgapor, mod_rewrite仍然经常使用GET。它只是允许将一个更友好的URL转换为一个带有GET查询字符串的URL。