How do you force a web browser to use POST when getting a url?

<form method="post">

If you're GETting a URL, you're GETting it, not POSTing it. You certainly can't cause a browser to issue a POST request via its location bar.


Use an HTML form that specifies post as the method:

<form method="post" action="/my/url/">
    ...
    <input type="submit" name="submit" value="Submit using POST" />
</form>

If you had to make it happen as a link (not recommended), you could have an onclick handler dynamically build a form and submit it.

<script type="text/javascript">
function submitAsPost(url) {
    var postForm = document.createElement('form');
    postForm.action = url;
    postForm.method = 'post';
    var bodyTag = document.getElementsByTagName('body')[0];
    bodyTag.appendChild(postForm);
    postForm.submit();
}
</script>
<a href="/my/url" onclick="submitAsPost(this.href); return false;">this is my post link</a>

If you need to enforce this on the server side, you should check the HTTP method and if it's not equal to POST, send an HTTP 405 response code (method not allowed) back to the browser and exit. Exactly how you implement that will depend on your programming language/framework, etc.


I have a feeling from your question you were just hoping to send a post request in a browser's address bar.

Just type the following into the address bar swapping the value for 'action' to the url that you like.

data:text/html,<body onload="document.body.firstChild.submit()"><form method="post" action="http://stackoverflow.com">

It's invalid html, but the browser's (at least all the ones i've tested it in so far) know what you mean, and I wanted to keep it as short as I could.

If you want to post values, append as many inputs as you like, swapping name and value in each input for whatever you like.

<input value="[email protected]" name="email">
<input value="passwordsavedinhistory" name="password">

It's important to note that sensitive information you post will be visible in:

  • your history
  • your address bar
  • your browser's autocomplete.
  • possibly other sites that you visit from the same tab
  • probably plenty of other things too

It's a really bad way to send a post request, and all the other answers are far better, but it's still cool that you can do it.

Tags:

Html

Http

Url

Post

Get