File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 12675
    
    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


Java Resources at www.wbrogden.com
 
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
 
Similar Threads
Confusion over JBossWS
How to create Web service using JAX-WS in Jboss
need help to consume webservice in Java
How to write a webservices client
Jersey RESTful web service - How to post XML file using jersey framework