user903772
user903772

Reputation: 1562

Httppost in groovy and grails

May I have sample codes to do manual http post in groovy and grails? I'm trying to post some strings to server.

Upvotes: 2

Views: 1026

Answers (2)

Bob Herrmann
Bob Herrmann

Reputation: 9938

The simpliest way,

Use an editor to a page (like below), open it in browser, click submit button

<form method="POST" action="http://slashdot.org/controller/action">
<input type=hidden name='boo' value='foo'>
<input type=submit>
</form>

edit page, reload, repeat.

Upvotes: 0

D&#243;nal
D&#243;nal

Reputation: 187399

If you want to send a POST request from the browser to the Grails app, then just use <g:form>

<g:form name="myForm" url="[action:'list',controller:'book']">...</g:form> 

By default Grails forms use the POST HTTP method.

If you want to send a POST to your Grails app, but don't want to build a form, there are about a million browser plugins/IDE plugins/desktop apps that allow you to construct HTTP requests. Examples include the REST Console plugin for Chrome and the HTTP Client plugin for Eclipse.

If you want to send a POST from your Grails app to some other URL, you'll need to use a Java/Groovy HTTP library to construct the request. Options include HTTPBuilder (Groovy) or Apache HTTP Client (Java).

Upvotes: 1

Related Questions