HTTP GET和POST参数建议 [英] HTTP GET and POST parameters recommendations
问题描述
发布以下POST请求是不好的做法:
/ test?a = 1& b = 2
POST数据:c = 3& d = 4
请注意,2个参数是URL的一部分和2个参数是POST内容的一部分。
- 在另一个注释中,以下规则仍然建议:
- GET请求:从
服务器检索内容,但不会在服务器上更改任何
。 - POST请求:post
内容到服务器,可能
修改服务器上的数据
我在问,因为我看到了一切在线。
Laurent Luce
是的,您的假设是正确的。你应该保持一致的方式来传递你的参数,或者要求传递参数,但这不会对你造成任何伤害。
GET操作应该是安全的操作,不会执行任何副作用(除了缓存等),所以它们很容易被代理等缓存。 POST操作可能会影响副作用。
我建议阅读:
$ b
GET
请求指定资源的表示。请注意,不应将GET用于导致副作用的操作,例如将其用于在Web应用程序中执行操作。其中一个原因是GET可能被机器人或抓取工具任意使用,因此不需要考虑请求应该导致的副作用。请参阅下面的安全方法。
POST
提交要处理的数据(例如从HTML表单)所识别的资源。数据包含在请求的正文中。这可能会导致创建新资源或更新现有资源或两者。
还有其他操作(例如HEAD ,PUT,DELETE),如果你正在设计一个API,你应该考虑使用它们。这些在RESTful API设计中进行了深入讨论。
Is it bad practice to issue the following POST request:
/test?a=1&b=2
POST data: c=3&d=4
Notice that 2 parameters are part of the URL and 2 parameters are part of the POST content.
On another note, is the following rule still recommended:
- GET request: retrieve content from the server but do not change anything on the server.
- POST request: post content to the server which may modify data on the server
I am asking because I see a bit of everything online.
Laurent Luce
Yes, your assumptions are correct. You should be consistent on how you pass your parameters or require the parameters to be passed, but it's not going to do any harm really.
GET operations are supposed to be safe operations, that don't perform any side-effects (besides caching, etc), so they are easily cached by proxies and such. POST operations on the other hand may encure side effects.
I would recommend reading the Wikipedia entry on HTTP protocol:
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. See safe methods below.
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.
There are other operations too (e.g. HEAD, PUT, DELETE), and you should consider using them if you are designing an API. These are heavily discussed in RESTful API design.
这篇关于HTTP GET和POST参数建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!