我正在尝试通过http帖子发送肥皂请求。根据显示https://t4t.services.telenet.be/TelemeterService?wsdl
的https://t4t.services.telenet.be/TelemeterService?xsd=1我需要发布一个ID和密码。
这是我的要求:
public static void main(String[] args) {
try {
callWebService("retrieveUsage");
} catch (IOException e) {
e.printStackTrace();
}
}
public static void callWebService(String soapaction) throws IOException {
String body = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:tns=\"http://www.telenet.be/TelemeterService/\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ><SOAP-ENV:Body><mns1:RetrieveUsageRequest xmlns:mns1=\"http://www.telenet.be/TelemeterService/\"><UserId>test</UserId><Password>test</Password></mns1:RetrieveUsageRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>";
HttpPost httppost = new HttpPost("https://t4t.services.telenet.be/TelemeterService");
// Request parameters and other properties.
StringEntity stringentity = new StringEntity(body, "UTF-8");
stringentity.setChunked(true);
httppost.setEntity(stringentity);
httppost.addHeader("Accept", "text/xml");
httppost.addHeader("SOAPAction", soapaction);
//Execute and get the response.
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
String strresponse = null;
if (entity != null) {
strresponse = EntityUtils.toString(entity);
}
System.out.println(strresponse);
System.out.println("Done");
}
我正在使用apache http。
strresponse是空的。
我的代码有问题吗?