http put with a working example

http put with a working example

 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

The method is not part of the URL.

How are you issuing the requests?

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

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.

  • Back aarticle:
  • Next aarticle: No
  • Copyright © 2007-2012 www.chuibin.com Chuibin Copyright