tags:

views:

132

answers:

2

I want to encode a URL such that it sends a POST request to a server. is that possible? and if so, how? I have searched around and mostly found that appending parameters to a url only sends them as parameters for GET request. is there a way to do that for POST request? basically, i am trying to implement a CSRF (not for malicious but testing purposes) and i want to be able to send a POST request to a server by encoding my url.

+2  A: 

GET and POST are HTTP methods. In GET the request parameters are taken as query string in the request URL. In POST the request parameters are taken as query string in the request body.

So you need to instruct whatever tool you're using to pass the parameters through the request body instead of the request URL along with a HTTP method of POST instead of (usually the default) GET.

Either way, the parameters just needs to be URL encoded anyway. There's no difference for POST or GET, unless you're setting the content encoding to multipart/form-data instead of (usually the default) application/x-www-form-urlencoded.

If you give more details about what programming language and/or library and/or framework you're using, then we may be able to give a more detailed answer how to invoke a HTTP POST request.

BalusC
+1  A: 

No. The method is not part of the Url. You'd have to make the request in such a way that it uses the post method. You didn't mention any details, but if it's from inside a document in the browser, you can either use a form:

<FORM action="someUrl.htm" method="post">

You can make a link that will send the form by javascript:

<form action="http://www.example.com/?param=value" method="post" id="someForm">
    <a href="#" onclick="document.getElementById('someForm').submit();">link</a>
</form>

or an XmlHttpRequest with javascript:

var xhr = new XMLHttpRequest();
xhr.open("POST", url);
...
Amitay Dobo
sorry if i wasn't clear, ok, so i want to create a link, which when clicked on, sends a POST request to a web server. This POST request is to behave same as the POST request sent by a form in a webpage on that server. And I want this URL for the browser. no code involved, as far as i understand. does that make sense?
urfriend
You can't do that with a link. If you want to do a POST, use a form submit button. You can always use CSS to style it so that it looks like a link.
bobince
Added an example of how to trigger the form submission by javascript. It does involve code, but it's all there in the onclick event handler.
Amitay Dobo
so is there a way to simulate a POST request as a GET request? or will it depend on the context? if a form sends a POST request to a server to post a message on a page. can that be implemented as a GET request?
urfriend