-1

次のリクエスト形式を残りの Web サービスに送信するにはどうすればよいですか?

<?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/を試してみてください。Android 用のバージョンもあります。

于 2012-11-07T09:28:36.840 に答える