Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the only way of passing POST parameters in HTML through a form?

Tags:

In HTML, you can send data from one page to another using a GET request in a couple of ways:

http://www.example.com/somepage.php?data=1 

...or...

<form action="somepage.php" method="get">   <input type="hidden" name="data" value="1" />   <input type="submit" value="Submit"> </form> 

With a POST request though, I've only seen data being sent through form elements like this:

<form action="somepage.php" method="post">   <input type="hidden" name="data" value="1" />   <input type="submit" value="Submit"> </form> 

If I only have one parameter I want to send to another page using POST, is there an easier way than wrapping it in a form?

like image 670
Philip Morton Avatar asked Nov 28 '08 14:11

Philip Morton


People also ask

Can we pass parameters in POST method?

In a POST request, the parameters are sent as a body of the request, after the headers. To do a POST with HttpURLConnection, you need to write the parameters to the connection after you have opened the connection.

What is POST method in HTML form?

POST: In the post method, after the submission of the form, the form values will not be visible in the address bar of the new browser tab as it was visible in the GET method. It appends form data inside the body of the HTTP request. It has no size limitation. This method does not support bookmark the result.

How can I pass POST parameters in a URL?

You could use a button instead of an anchor and just style the button to look like a link. That way you could have your values in hidden fields inside the same form to be sent via POST. In addition to what Ben said, you can also let the link be a dummy and have it execute a javascript that submits a hidden form.

How are POST parameters sent?

Short answer: in POST requests, values are sent in the "body" of the request. With web-forms they are most likely sent with a media type of application/x-www-form-urlencoded or multipart/form-data .


1 Answers

There are only two ways to POST from a browser - a form, or an Ajax request.

like image 93
Greg Avatar answered Oct 21 '22 00:10

Greg