开发者

How to Build an HTML POST?

开发者 https://www.devze.com 2023-03-31 06:44 出处:网络
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.

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://h开发者_开发百科ost.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.


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.

<form method="post" enctype="multipart/form-data"><!--values here--></form>

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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号