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?
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.
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.
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.
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 .
There are only two ways to POST from a browser - a form, or an Ajax request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With