public void haha(String sss) throws Exception {
String wsdl = "http://10.0.9.103/vms/services/VmsSdkWebService";
int timeout = 10000;
StringBuffer sb = new StringBuffer("");
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
sb.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<soapenv:Body>"
+ "<applyToken xmlns=\"http://ws.vms.ivms6.hikvision.com\"> "
+ "<arg0 xmlns=\"\"> "+sss+" </arg0>"
+ "</applyToken> "
+ "</soapenv:Body>"
+ "</soapenv:Envelope>"
);
// 打印请求soap
System.out.println("Soap:" + sb.toString());
// HttpClient发送SOAP请求
HttpClient client = new HttpClient();
PostMethod postMethod = new PostMethod(wsdl);
// 设置连接超时
client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout);
// 设置读取时间超时
client.getHttpConnectionManager().getParams().setSoTimeout(timeout);
// 然后把Soap请求数据添加到PostMethod中
RequestEntity requestEntity = new StringRequestEntity(sb.toString(), "text/xml", "UTF-8");
//设置请求头部,否则可能会报 “no SOAPAction header” 的错误
postMethod.setRequestHeader("SOAPAction","applyToken");
// 设置请求体
postMethod.setRequestEntity(requestEntity);
int status = client.executeMethod(postMethod);
// 打印请求状态码
System.out.println("status:" + status);
// 获取响应体输入流
InputStream is = postMethod.getResponseBodyAsStream();
// 获取请求结果字符串
String result = IOUtils.toString(is,"UTF-8");
System.out.println("result: " + HikUtils.getResault(result));
// HttpURLConnection 发送SOAP请求
System.out.println("HttpURLConnection 发送SOAP请求");
URL url = new URL(wsdl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
conn.setRequestMethod("POST");
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setConnectTimeout(timeout);
conn.setReadTimeout(timeout);
DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
dos.write(sb.toString().getBytes("utf-8"));
dos.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
String line = null;
StringBuffer strBuf = new StringBuffer();
while ((line = reader.readLine()) != null) {
strBuf.append(line);
}
dos.close();
reader.close();
System.out.println(strBuf.toString());
}