开发者

POST xml file using http request on Android

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜