开发者

POST xml file using http request on Android

开发者 https://www.devze.com 2023-01-27 22:50 出处:网络
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.

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!!!!


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); 


Feel free to reuse this helper class from ACRA.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消