httpclient调用webservice推送soap

public static String ncgConnection(String wsdUrl, String params) {
URL wsUrl;
String result="";
try {
wsUrl = new URL(wsdUrl);
HttpURLConnection conn = (HttpURLConnection) wsUrl.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod(“POST”);
conn.setRequestProperty(“Content-Type”, “text/xml;charset=UTF-8”);
conn.setRequestProperty(“SOAPAction”,“urn:SpdMessage”);
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
OutputStream os = conn.getOutputStream();
String soap = “<soapenv:Envelope xmlns:soapenv=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:urn=“urn:hl7-org:v3”>” +
“soapenv:Header/” +
“soapenv:Body” +
“” +
“<apply_data>”+
params+
“</apply_data>”+
“” +
“</soapenv:Body>” +
“</soapenv:Envelope>”;
System.out.println(“包装后的参数为:”+params);
os.write(soap.getBytes());
int code = conn.getResponseCode();
System.out.println(“返回的code为:”+code);
InputStream is;
if (code == 200) {
is = conn.getInputStream();
} else {
is = conn.getErrorStream();
}
byte[] b = new byte[2048];
int len = 0;
String s = “”;
while((len = is.read(b)) != -1){
String ss = new String(b,0,len,“UTF-8”);
System.out.println(“收到的ss为:”+ss);
s += ss;
}
System.out.println(“收到的s为:”+s);
result=s.split("<apply_data>")[1].split("</apply_data>")[0];
System.out.println(“得到的返回值为:”+result);
is.close();
os.close();
conn.disconnect();
} catch (MalformedURLException e) {
System.out.println(“通讯模块1:”+e.getMessage());
} catch (IOException e) {
System.out.println(“通讯模块2:”+e.getMessage());!

}
return result;

}

在请求头中设置Content-Type,SOAPAction这两个设置错误会报错。The endpoint reference (EPR) for the Operation not found…

在这里插入图片描述

可以使用soapui访问后会得到如图。根据如图去添加请求头的信息。

消息内容的封装:
在这里插入图片描述

根据soapUI的访问内容封装。
soap1.2也根据soapui去封装。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值