如何构建 HTML POST?
与 GET 构建查询非常简单(将字段连接到一个长 URL 中)不同,我似乎缺少生成 POST 的“秘密”。
我知道
由于某种原因,我发现的关于这个主题的教程对此仍然很神秘。
如何构建 HTML POST?
这是加载到浏览器中的简单 URL 字符串吗?或者还有更多的事情吗?
答案是否取决于浏览器/平台,我在 Android 上使用 WebView。
Unlike GET
, in which building the query is straightforward (concatenating fields into one long URL), I seem to be missing the "secret" of generating a POST
.
I know that the URL provided in the <FORM ACTION="https://host.domain.com/etc">
should be used in some way, but how?
The tutorials I found on this subject remain mysterious about this for some reason.
How do I build an HTML POST?
Is that a straightforward URL string loaded into the browser? or is there more to it?
Is the answer is browser/platform dependent, I am using WebView on Android.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,如果您使用 HTML,它应该与您在浏览器上执行的方式相同。
也就是说,将 method 属性添加到表单标记中,如果您正在使用文件,则添加 enctype 属性。
我建议您阅读关于 POST 的维基百科页面: http://en.wikipedia.org/wiki/POST_ (HTTP)
基本上,它不是将数据编码在 url 中,而是将其发送到消息正文中。
另请参阅:http://www.cs.tut.fi/~jkorpela/ forms/methods.html
除了向用户“隐藏”查询数据之外,它还用于上传文件,因为您可以包含二进制数据而不仅仅是文本。
如果您想在使用表单时保持网址干净,这非常有用。
(例如,您在表单数据中包含一个长字符串,则 url 会变得非常长。)
此外,浏览器通常会在用户刷新表单页面时提示用户。
浏览器不会为 GET 执行此操作,这通常用于导航或将参数传递到服务器,用户可能会发现这些参数对于直接更改自己很有用。 (即 page_id=1,用户可以通过更改单个数字来转到下一页或特定页面。)
Well, if you're working with HTML, it should be the same way that you would do it on the browser.
That is, add a method attribute to your form tag and if you're working with files a enctype attribute.
I suggest you read the wikipedia page on POST: http://en.wikipedia.org/wiki/POST_(HTTP)
Basically, instead of encoding the data in the url it sends it in a message body.
Also see: http://www.cs.tut.fi/~jkorpela/forms/methods.html
Beside it 'hides' the query data from the user, it is used for uploading files because you can include binary data and not just text.
This is useful if you want to keep your urls clean when working with forms.
(For example, you include a long string in your form data the url will get really long.)
Also, the browser will usually prompt the user when they refresh a form page.
The browser won't do this for GET, this is usually used for things like navigation or for passing parameters to the server that the user might find useful to change themselves directly. (i.e. page_id=1 and the user can just go to the next page or a specific page by changing a single number.)