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 do I make a HttpPost request to RESTful webservice same as HttpGet where passing an URL with par Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "How do I make a HttpPost request to RESTful webservice same as HttpGet where passing an URL with par" Watch "How do I make a HttpPost request to RESTful webservice same as HttpGet where passing an URL with par" New topic
Author

How do I make a HttpPost request to RESTful webservice same as HttpGet where passing an URL with par

Pallab Islam
Greenhorn

Joined: Jun 25, 2013
Posts: 3
I am trying to make a call to a RESTful webservice to get JSON object. Now I tried making the call through HttpGet and was successful. The URL I pass through HttpGet right now is pretty much like this: http://abc.com/ /Ordering.ashx?Name=save&Code=sample&OrderDetails=[{“Count”: “2”, “ID”: “1”, “Price”: “5”}, {“Count”: “2”, “ID”: “2”, “Price”: “5”}].

And the way I am doing it:
`


`

Now, what should I do if I want to make HttpPost call instead of HttpGet call? I tried in this way,



Instead of inParameters = new ArrayList<NameValuePair>(), I also tried with Bundle b = new Bundle() and onwards. Nothing works!
Now I am not sure how should I add the values pairs in OrderDetails=[{“Count”: “2”, “ID”: “1”, “Price”: “5”}, {“Count”: “2”, “ID”: “2”, “Price”: “5”}] in the Post call and how should I execute it to get the same JSON object in as I am getting while making HttpGet call. I am also not sure if I need to add HttpHeader for this. I am working on a android project. I am a new programmer, so not very known to these issues. Please help.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Note that RESTful architecture makes a VERY clear distinction between GET and POST

A GET request gets the current state of a resource without modifying it. You will see the term idempotent when refering to the result of a GET.

A POST request should only be used when you are modifying a resource. This is NOT idempotent.

Bill
Pallab Islam
Greenhorn

Joined: Jun 25, 2013
Posts: 3
Thanks for the reply. I couldn't get it properly. Could you please explain a little bit more.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Did you read the Wikipedia article on RESTful or any of the Web Services FAQ here at the ranch? I really see no reason for me to duplicate these articles in a post.

If you try to make a POST do the same thing as a GET then you are not writing a RESTful web service.

RESTful is an architecture / design philosophy intended to produce clarity of design.

Bill
Pallab Islam
Greenhorn

Joined: Jun 25, 2013
Posts: 3
William Brogden wrote:Did you read the Wikipedia article on RESTful or any of the Web Services FAQ here at the ranch? I really see no reason for me to duplicate these articles in a post.

If you try to make a POST do the same thing as a GET then you are not writing a RESTful web service.

RESTful is an architecture / design philosophy intended to produce clarity of design.

Bill


Thanks for the suggestion. I am actually new to web services, so I will better go through the articles and faq again.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How do I make a HttpPost request to RESTful webservice same as HttpGet where passing an URL with par
 
Similar Threads
Android and JSP
Post the data to Server
Single Sign On
Apache httpClient
getParameter in jsp file sent by HttpClient