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());
}
}
下面介绍
首先我们先下载一个叫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());
}
}
下面介绍
相关文章推荐
- RPC failed; result=22, HTTP code = 411
- HTTP Header 属性列表
- nginx中http核心模块的配置指令2
- nginx中http核心模块的配置指令3
- nginx中http核心模块的配置指令4
- nginx中http的fastcgi模块的配置指令1
- 如何在 Linux 中快速地通过 HTTP 提供文件访问服务
- 深入HTTP head的使用详解
- ASP 中使用 HTTP 协议发送参数详解
- C#基于socket模拟http请求的方法
- http www安全必备知识
- asp HTTP 500错误 常见问题分析
- SQL Server Native Client下载 SQL Server Native Client安装方法
- http代理相关知识分析
- 在Node.js中使用HTTP上传文件的方法
- php错误提示failed to open stream: HTTP request failed!的完美解决方法
- php提示Failed to write session data错误的解决方法