1

I'm trying to POST the following xml to a server url, but i don't know how to go about it. GET requests are easy enough, but I'm having a problem with POST requests.

<?xml version="1.0" encoding="utf-16"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>the_command</string>
</ArrayOfString>

I need to be able to modify 'the_command' at run-time before making the request. Any help will be appreciated!!!!

3 Answers 3

3

you can try this one -

StringBuilder sb = new StringBuilder();

sb.append("<ArrayOfString>");
sb.append("<string>").sb.append("the_command").sb.append("</string>");
sb.append("</ArrayOfString>");

StringEntity entity = new StringEntity(sb.toString(), "UTF-8");
httppost.setEntity(entity);  
httppost.addHeader("Accept", "application/xml");
httppost.addHeader("Content-Type", "application/xml");

HttpResponse response = httpclient.execute(httppost); 
Sign up to request clarification or add additional context in comments.

Comments

0

Feel free to reuse this helper class from ACRA.

Comments

0

Use StringBuffer to store the content of XML file and finally send it to the server using Get or Post method.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.