Search code examples
androidhttp-put

How to add XML data to HttpPut object?


I have a small problem. I am testing my Android REST class on http://www.thomas-bayer.com/sqlrest/CUSTOMER DEMO REST service.

Get method is OK, but I don't know how to use HttpPut or HttpPost.

HttpPut request = new HttpPut("http://www.thomas-bayer.com/sqlrest/CUSTOMER/-2223");

But then I don't know how to add to this object XML data to put on server, for example:

<CUSTOMER xmlns:xlink="http://www.w3.org/1999/xlink">
<ID>2</ID>
<FIRSTNAME>Rick</FIRSTNAME>
<LASTNAME>Cortés Ribotta</LASTNAME>
<STREET>Calle Pública "B" 5240 Casa 121</STREET>
<CITY>Sydney100</CITY>
</CUSTOMER>

Thank you very much for answer.


Solution

  • You have to set the XML content via setEntity where the Entity has to be a StringEntity.

    mystr = ... // your XML
    HttpPut request= new HttpPut(url);
    request.setEntity(new StringEntity(mystr));