http - 那么为什么我们应该使用 POST 而不是 GET 来发布数据呢?

标签 http post

<分区>

Possible Duplicates:
How should I choose between GET and POST methods in HTML forms?
When do you use POST and when do you use GET?

显然,你应该这样做。但是这样做除了为了履行HTTP协议(protocol)之外,还有什么理由这样做呢?更少的开销?某种安全措施?

最佳答案

因为 GET 不能根据定义改变服务器的状态。

参见 RFC2616 9.1.1 Safe Methods :

9.1.1 Safe Methods

Implementors should be aware that the software represents the user in their interactions over the Internet, and should be careful to allow the user to be aware of any actions they might take which may have an unexpected significance to themselves or others.

In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe". This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested.

如果您使用 GET 来更改服务器的状态,那么搜索引擎机器人或 Web 浏览器中的某些链接预取扩展可能会对您的站点造成严重破坏,并且(例如)delete all user data just by following links to your site .

关于http - 那么为什么我们应该使用 POST 而不是 GET 来发布数据呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1254132/

相关文章:

javascript - 是否可以将 JavaScript 或样式表 (CSS) 保存到/从浏览器的本地数据库加载?

http - Golang 中的 "Invalid memory address"使用 ioutil.ReadAll()

java - Netbeans Maven无法执行项目目标

php - 使用 PHP 读取 JSON POST

PHP 发布并获取值到 jQuery 框页面,刷新页面为 `msnbc.com`

ajax - Django csrf_token 在 Chrome 中为空

ios - 给定网站的 Swift 中的 POST 查询

来自 HTTP 拦截器的 Angular 4 HTTP 请求

java - Retrofit2不发送POST数据

ios - 如何发送带有文本参数和图像文件的帖子数据?