Html HTTP post:url参数和表单数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4005327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTTP post: url parameters and form data
提问by Bogdan Gusiev
When I do http POST request via Web form, Is there any difference(practically or theoretically) between parameters specified in the URL and parameters passed with form on the server side?
当我通过 Web 表单执行 http POST 请求时,URL 中指定的参数与服务器端通过表单传递的参数之间是否有任何区别(实际上或理论上)?
Can I do whole POST with url parameters and expect same result as with form inputs?
我可以使用 url 参数执行整个 POST 并期望与表单输入相同的结果吗?
Like:
喜欢:
<form action="/?id=2" method="post">
<input type="text" name="name" value="John"/>
<input type="submit" value="submit"/>
</form>
Or:
或者:
<form action="/?id=2&name=John" method="post">
<input type="submit" value="submit"/>
</form>
Thanks.
谢谢。
采纳答案by Dave
The references Gabriel and BrokenGlass provided are really cool, but let me give you me 2 cents.
Gabriel 和 BrokenGlass 提供的参考资料真的很酷,但让我给你 2 美分。
I'm supposing you already know a little about how to retrieve data sent from the form on the server-side. If you don't, start there and the answers will come faster than you could imagine.
我假设您已经对如何在服务器端检索从表单发送的数据有所了解。如果你不这样做,从那里开始,答案会比你想象的更快。
Well, parameters sent on the URL or the form's attribute action are GET data parameters. They will be parsed and made available as such. Period.
好吧,在 URL 或表单的属性操作上发送的参数是 GET 数据参数。它们将被解析并提供。时期。
The input fields from a form with method POST are sent as POST data and are parsed and available as such.
来自具有 POST 方法的表单的输入字段作为 POST 数据发送,并被解析和可用。
From examples you gave, and supposing you are using PHP, we could retrieve the following:
从您提供的示例中,假设您使用的是 PHP,我们可以检索以下内容:
Example 1
示例 1
$_GET['id']
$_POST['name']
Example 2
示例 2
$_GET['id']
$_GET['name']
Hope the concepts are clear.
希望概念清楚。
回答by Gabriel McAdams
You should read this articleon the differences between GET and POST (GET is when you put your parameters in the URL, and POST is when you put your parameters in the form).
您应该阅读这篇文章,了解 GET 和 POST 之间的区别(GET 是将参数放入 URL 中,POST 是将参数放入表单中)。
Also, this question has already been answered here on StackOverflow
另外,这个问题已经在 StackOverflow 上得到了回答