最も簡単な方法は、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;
}