Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

http put with a working example  RSS feed

 
Sindhuri krish
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

I am new to webservices and have been trying to update an existing item using httpput

Appreciate if you can please give me an example of http put and http post with a generic webservice url I can also use

Have read the theoritical part of http post and http put. I was able to post an data using httppost and get the posted content too.But was unable to find the exact url to update the posted data using PUT

Thanks in advance



 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method is not part of the URL.

How are you issuing the requests?
 
Sindhuri krish
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:The method is not part of the URL.

How are you issuing the requests?


I am using the requests below way:

HttpPut httpput=new HttpPut(url);

HttpResponse response = httpclient.execute(httpput);
HttpEntity entity = response.getEntity();
if (entity != null)

Sop("success")
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sindhuri krish wrote:But was unable to find the exact url to update the posted data using PUT

I don't understand what you mean by this. URL and method are not closely related concepts. Whatever resource is handling the URL you're accessing needs to be set up to handle PUT. In a typical REST scenario, the resource would normally handle all methods (GET, POST, PUT, DELETE), possibly returning an error if a particular method is not applicable to that resource.

What kind of resource are you accessing - a servlet? A JAX-RS resource? Something else? Seeing some relevant parts of the server-side code would help.
 
Sindhuri krish
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:
Sindhuri krish wrote:But was unable to find the exact url to update the posted data using PUT

I don't understand what you mean by this. URL and method are not closely related concepts. Whatever resource is handling the URL you're accessing needs to be set up to handle PUT. In a typical REST scenario, the resource would normally handle all methods (GET, POST, PUT, DELETE), possibly returning an error if a particular method is not applicable to that resource.

What kind of resource are you accessing - a servlet? A JAX-RS resource? Something else? Seeing some relevant parts of the server-side code would help.


Apologies about confusion I caused. I am trying to use the same url in PUT which worked fine in GET

url="servername/abc/xyz/id"

1.HttpGet of above url returns xml response

2.Save the above xml response to local

3.Open the above saved file and edit one of the xml node values and save the xml

4.HttpPut the saved file in step 4 expected the resource to get updated

When I run the java file , I get HTTP/1.1 400 Bad Request

My question was to ask if I can use the same url for both HttpGet and HttpPut

Thanks

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:What kind of resource are you accessing - a servlet? A JAX-RS resource? Something else? Seeing some relevant parts of the server-side code would help.


While most server-side end points can handle a GET or a POST (or at least respond with a meaningful error message), most wouldn't accept a PUT unless especially configured to do so.
 
Sindhuri krish
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:
Ulf Dittmer wrote:What kind of resource are you accessing - a servlet? A JAX-RS resource? Something else? Seeing some relevant parts of the server-side code would help.


While most server-side end points can handle a GET or a POST (or at least respond with a meaningful error message), most wouldn't accept a PUT unless especially configured to do so.


Thanks Dittmer, seeing server side code helped
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!