一個最簡單的方法是創建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;
}
那我怎麼讀迴應呢? – user1805605