码迷,mamicode.com
首页 > Web开发 > 详细

webService 使用 httpClient httpCore 学习

时间:2016-02-23 19:20:32      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:webservicre httpclient httpcore

一种基于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);// WSDLURL 就是提供的WSDL

try {

HttpEntity re = new StringEntity(reqSoapData, "UTF-8");

post.setHeader("Content-Type", "text/xml;charset=UTF-8");

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());

}


下面介绍

本文出自 “7619052” 博客,请务必保留此出处http://7629052.blog.51cto.com/7619052/1744331

webService 使用 httpClient httpCore 学习

标签:webservicre httpclient httpcore

原文地址:http://7629052.blog.51cto.com/7619052/1744331

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!