Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

http

post

url

get

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

like image 821
Daniel Kivatinos Avatar asked Oct 30 '09 17:10

Daniel Kivatinos


People also ask

Can you make POST request from browser?

You cannot make a POST request by using a web browser, as web browsers only directly support GET requests. For this example, we assume that you have installed a REST client browser plugin. Chrome and Firefox both support open source Rest Client plugins that allow for the invocation of REST APIs from the browser.

How do I request a POST from a URL?

POST request in itself means sending information in the body. I found a fairly simple way to do this. Use Postman by Google, which allows you to specify the content-type (a header field) as application/json and then provide name-value pairs as parameters. Just use your URL in the place of theirs.

Why URL is not exposed in post method?

In case of post request, large amount of data can be sent because data is sent in body. 2) Get request is not secured because data is exposed in URL bar. Post request is secured because data is not exposed in URL bar.

How do I make a HTTP POST request in Chrome?

Type the url in the main input field and choose the method to use: GET/POST/PUT/DELETE/PATCH. Click on the arrow "Send" or press Ctrl+Enter. You'll see info about the response (time, size, type) and you'll be able to see the content response in the response section.


1 Answers

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.

like image 71
Asaph Avatar answered Sep 21 '22 16:09

Asaph