【问题标题】:POST xml file using http request on Android在 Android 上使用 http 请求 POST xml 文件
【发布时间】:2010-12-03 06:08:58
【问题描述】:

我正在尝试将以下 xml 发布到服务器 url,但我不知道该怎么做。 GET 请求很简单,但是我遇到了 POST 请求的问题。

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

在发出请求之前,我需要能够在运行时修改“the_command”。 任何帮助将不胜感激!!!!

【问题讨论】:

    标签: java android http


    【解决方案1】:

    你可以试试这个 -

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

    【讨论】:

      【解决方案2】:

      随意重复使用this helper class from ACRA

      【讨论】:

        【解决方案3】:

        使用StringBuffer存储XML文件的内容,最后通过Get或Post方法发送到服务器。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-10-03
          • 2012-07-10
          • 2013-02-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多