Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Pallab Islam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic