java - How to do HTTPPUT request using XML? -


i learning rest api , find difficult put request. below code tried. record doesn't updated successfully

the url used - http://www.thomas-bayer.com/sqlrest/product/1

value trying update - <price>24.8</price> <price>24.9</price>

language : java

defaulthttpclient httpclient = new defaulthttpclient();     httpput putrequest = new httpput(             "http://www.thomas-bayer.com/sqlrest/product/1");     list<namevaluepair> nvps = new arraylist<namevaluepair>() {{         add(new basicnamevaluepair("content-type", "application/xml"));         add(new basicnamevaluepair("server", "apache-coyote/1.1"));      }};     (namevaluepair h : nvps) {         putrequest.addheader(h.getname(), h.getvalue());     }     string xml="<?xml version=\"1.0\"?><product xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n" +             "    <id>1</id>\n" +             "    <name>chair shoe</name>\n" +             "    <price>24.9</price>\n" +             "</product>";      putrequest.setentity(new stringentity(xml));      httpresponse response = httpclient.execute(putrequest);      if (response.getstatusline().getstatuscode() != 201) {         throw new runtimeexception("failed : http error code : "                 + response.getstatusline().getstatuscode());     }      httpclient.getconnectionmanager().shutdown(); } 

i 500 response able add record if record not there using httpput. how fix this?


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -