-1

我希望将以下请求格式发送到其余网络服务我该怎么做?

<?xml version="1.0" encoding="UTF-8"?>
<demo>
<headers>
  <messagetype>1</messagetype>
  <messagetoken>123647356734156</messagetoken>
</headers>
<authentication>
  <name>xxx</name>
  <servicename>yyy</servicename>
  <username>10121</username>
  <password>welcome1234</password>
</authentication>
</demo>
4

2 回答 2

1

最简单的方法是创建一个带有 XML 请求值的字符串。例如,您可以将此 XML 字符串请求值传递给以下函数以从服务器获取响应。

仅供参考,您可以通过在 HTTPPost 对象内设置实体值来传递请求,与以下示例相同。您也可以通过这种方式传递 JSON 请求值。

例如:

public HttpResponse postData(String strXML) {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("web service URL");

    try {
        StringEntity strEntity = new StringEntity(strXML,HTTP.UTF_8);
        strEntity.setContentType("text/xml");  
        httppost.setHeader("Content-Type","application/soap+xml;charset=UTF-8");
        httppost.setEntity(strEntity);  // here you can set request value.

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        return response;
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }

    return null;
} 
于 2012-11-07T09:28:45.703 回答
0

尝试 reslet http://www.restlet.org/他们也有安卓版本..

于 2012-11-07T09:28:36.840 回答