It's not a secret anymore!*
The moose likes Web Services and the fly likes How to Write a Java Client to consume REST webservice using POST method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "How to Write a Java Client to consume REST webservice using POST method" Watch "How to Write a Java Client to consume REST webservice using POST method" New topic
Author

How to Write a Java Client to consume REST webservice using POST method

Azahrudhin Mohammad
Greenhorn

Joined: Sep 04, 2012
Posts: 18

Hi Guys,
Could any one please help to post the java client to consume the REST webservice using POST method.

say I have web service like http://localhost:8080/MyWs/sayHello/ (as it is REST not wsdl)

Browser Call will be :
http://localhost:8080/MyWs/sayHello/Peter/Hai
http://localhost:8080/MyWs/sayHello?name=Peter&msg=Hai (In case of GET)

If I wanted to write java client how can i write. (How to pass the String or request parameter and make rest call , No wsdl)


Thanks and Regards,
azahrudhin.mohd@gmail.com
Surender Suri
Ranch Hand

Joined: May 28, 2010
Posts: 42
You can use java.net.HttpUrlConnection (or) use apache client, check this http client


Thanks,
Suri
Azahrudhin Mohammad
Greenhorn

Joined: Sep 04, 2012
Posts: 18

Hi Suri,
Thanks for the quick reply.
could you please advice on below code sinipet as I am already using the HttpUrlConnection but don't know how to pass the values as part of request.

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
See this Wikipedia article on the POST format.

The body of your POST request will consist of line after line of these name=value parameters.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Write a Java Client to consume REST webservice using POST method