下面是java用httpclient做的webservice客户端,现在想知道怎么服务端怎么接受这个soapRequestData xml数据并返回一个xmlpublic static void testHttpClientWebservice(){
String soapRequestData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap12:Envelope xmlns:xsi=\" "<soap12:Body>" +
" <getCountryCityByIp xmlns=\" " <theIpAddress>221.226.1.218</theIpAddress>" +
" </getCountryCityByIp>" +
" </soap12:Body>" +
"</soap12:Envelope>";
PostMethod postMethod =new PostMethod(" http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx");
byte[] b;
try {
postMethod.setRequestBody(new NameValuePair[] {
new NameValuePair("test" , soapRequestData)
});
b = soapRequestData.getBytes("utf-8");
InputStream is = new ByteArrayInputStream(b,0,b.length);
RequestEntity re = new InputStreamRequestEntity(is,b.length,"application/soap+xml; charset=utf-8");
postMethod.setRequestEntity(re);
HttpClient httpClient = new HttpClient();
int statusCode = httpClient.executeMethod(postMethod);
System.out.println(postMethod.getResponseBodyAsString());
} catch (IOException e) {
e.printStackTrace();
}
}
String soapRequestData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap12:Envelope xmlns:xsi=\" "<soap12:Body>" +
" <getCountryCityByIp xmlns=\" " <theIpAddress>221.226.1.218</theIpAddress>" +
" </getCountryCityByIp>" +
" </soap12:Body>" +
"</soap12:Envelope>";
PostMethod postMethod =new PostMethod(" http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx");
byte[] b;
try {
postMethod.setRequestBody(new NameValuePair[] {
new NameValuePair("test" , soapRequestData)
});
b = soapRequestData.getBytes("utf-8");
InputStream is = new ByteArrayInputStream(b,0,b.length);
RequestEntity re = new InputStreamRequestEntity(is,b.length,"application/soap+xml; charset=utf-8");
postMethod.setRequestEntity(re);
HttpClient httpClient = new HttpClient();
int statusCode = httpClient.executeMethod(postMethod);
System.out.println(postMethod.getResponseBodyAsString());
} catch (IOException e) {
e.printStackTrace();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货