我想通过Android调用webservice。我需要通过HTTP POST一些XML到一个URL。
我发现这削减了发送POST,但我不知道如何包括/添加XML数据本身。
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.10.4.35:53011/");
try {
// Add your data
List nameValuePairs = new ArrayList(2);
nameValuePairs.add(new BasicNameValuePair("Content-Type", "application/soap+xml"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Where/how to add the XML data?
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
这是我需要模仿的完整的POST消息:
POST /a8103e90-f1e3-11dd-bfdb-8b1fcff1a110 HTTP/1.1
Host: 10.10.4.35:53011
Content-Type: application/soap+xml
Content-Length: 602
urn:uuid:fc061d40-3d63-11df-bfba-62764ccc0e48
http://schemas.xmlsoap.org/ws/2004/09/transfer/Get
urn:uuid:a8103e90-f1e3-11dd-bfdb-8b1fcff1a110
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous