HTTP POST 请求中的 URL 参数可以吗?
我正在使用一些 HTML 表单,我只想知道即使方法属性是 POST,是否可以在操作属性中使用 URL 参数?
<form action="index.php?somefield=someval" method="post">
<input name="anotherfield" value="anothervalue" type="text" />
<input type="submit" />
</form>
好吧,这工作正常,我可以在回发页面中获取所有字段及其值,但我想知道这样做是否违反了某些规则、标准或其他内容?如果可以的话,请展示一些可以证明它没问题的资源,因为我在 W3.org 中找不到它。
I'm working with some HTML forms and I just want to know if it is okay to use a URL parameters in the action attribute even if the method attribute is POST?
<form action="index.php?somefield=someval" method="post">
<input name="anotherfield" value="anothervalue" type="text" />
<input type="submit" />
</form>
Well, this works fine, I can get all fields and their values in my postback page but I want to know if I'm breaking some rules, standard or something by doing this? Please, if you can, show some resource that can prove it is okay because I can't find it in W3.org.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如规范 RFC1866 第 8.2.3 节 所述:
发送
POST
请求时,表单数据实际上是在请求正文中发送的,而不是在标头中发送的。因此请求 URL(表单的action
)与请求正文不同。后台发送到服务器的数据如下所示:
As the specifications RFC1866 section 8.2.3 states that:
When sending a
POST
request, the form data is actually sent in the body of the request, not in the header. So the request URL (the form'saction
) is different from the request body.The data sent to the server in the background looks like this:
只要你的代码是一致的并且可以工作,你就应该没问题。仅在有理由的情况下才分离参数,然后将其记录下来,以便稍后出现的任何人都清楚原因。
当然,还要对其进行测试以确保其有效。它可能不是标准的,但如果你有某种原因,没有什么可以说你不能这样做。
As long as your code is consistent and works you should be fine. Only seperate the parameters if you have a reason to, and then document it so its clear why to anyone who comes along later.
And of course test it to make sure it works. Its probably not standard, but if you have some reason there's nothing to say you can't do it.
它有效,但有时会令人困惑。如果您的 somefield=someval 与您的表单相关,那么最好这样做:
但是如果您的 somefield=someval 与表单无关,那么您应该将其保留为 GET,这样它就不会成为表单数据的一部分。
It works, but can sometimes be confusing. If your somefield=someval is relevant to your form, it's probably better to do:
But if your somefield=someval is irrelevant from the form then you should keep it as GET so it doesn't become part of your form data.
您可以使用 $_REQUEST["name"] 从 get 或 post 模式获取值。 查看 < /a>了解更多详情
you can use $_REQUEST["name"] to get values from both get or post mode. Check out for more details