您的位置:首页 > 理论基础 > 计算机网络

webService 使用 httpClient httpCore 学习

2016-02-23 16:24 573 查看
一种基于http协议使用WebService方法
首先我们先下载一个叫SoapUI的软件 (直接百度)
安装这个就不用多说。
使用:
1.创建一个SOAP project




填入WSDL



然后会解析出来一些数据。找到我们想要对接的接口 比如我对接的方法是



双击打开是:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:update_Lianbi_info>
<!--Optional:-->
<tem:USERID>?</tem:USERID>
<!--Optional:-->
<tem:SN>?</tem:SN>
<!--Optional:-->
<tem:OLD_LBSN>?</tem:OLD_LBSN>
<!--Optional:-->
<tem:NEW_LBSN>?</tem:NEW_LBSN>
</tem:update_Lianbi_info>
</soapenv:Body>

以及



</soapenv:Envelope>

这个就是我们即将需要的。

Java代码
public void SendLianbiWebService()throws ParseException, IOException {
HttpClient client = HttpClients.createDefault();
String reqSoapData = buildReqSoapData(liBiEntity);//此处就是拼接SOAP请求
HttpPost post = new HttpPost(WSDLURL);// [b]WSDLURL 就是提供的WSDL[/b]
try {
HttpEntity re = new StringEntity(reqSoapData, "UTF-8");
post.setHeader("[b]Content-Type", "text/xml;charset=UTF-8");[/b]
post.setHeader("Accept-Encoding", "gzip,deflate");
post.setHeader("SOAPAction","http://tempuri.org/IWarehouse_Business/update_change_Lianbi_info");
post.setEntity(re);
response = client.execute(post);//发送请求
returnInfo = EntityUtils.toString(response.getEntity());
log.info("请求服务返回XML文本:" + returnInfo);
} catch (UnsupportedEncodingException e) {
log.error(e.getStackTrace());
} catch (ClientProtocolException e) {
log.error(e.getStackTrace());
} catch (IOException e) {
log.error(e.getStackTrace());
}
}

下面介绍
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  http Client webservicre