Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Azahrudhin Mohammad
Greenhorn
Posts: 18
Hibernate Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)

 
Surender Suri
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use java.net.HttpUrlConnection (or) use apache client, check this http client
 
Azahrudhin Mohammad
Greenhorn
Posts: 18
Hibernate Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic