使用HttpClient发送WebService Security(WSS)请求

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

                  使用HttpClient发起普通的WebService还是非常方便的,为了测试代码能够正常运行,最好是先准备以下的JAR包:
    commons-codec-1.3.jar
    commons-httpclient-3.1.jar
    commons-logging-1.1.1.jar
    not-yet-commons-ssl-0.3.11.jar
    saxon-9.1.0.8j.jar
    wsdl4j-1.6.2-fixed.jar
    wss4j-1.5.8.jar
    xalan-2.7.1.jar
    xbean-fixed-2.4.0.jar
    xbean_xpath-2.4.0.jar
    xercesImpl.jar
    xml-apis-2.9.1.jar
    xml-apis.jar
    xmlpublic-2.4.0.jar
    xmlsec-1.4.3.jar

    这里先看一个简单的调用示例,几行代码就可以搞定:   

public static void sendWSRequest() throws IOException, SAXException, ParserConfigurationException{     String soapRequestXml = "(You soapRequest Xml)";        PostMethod postmethod = new PostMethod("http://****/soapAddress");        byte[] b = soapRequestXml.getBytes("UTF-8");        InputStream is = new ByteArrayInputStream(b, 0, b.length);        RequestEntity re = new InputStreamRequestEntity(is, b.length,"application/xop+xml; charset=UTF-8; type=\"text/xml\"");        postmethod.setRequestEntity(re);        HttpClient httpClient = new HttpClient();        httpClient.executeMethod(postmethod);        System.out.println(postmethod.getResponseBodyAsString());    } 
    这里的soapReuqestXml是符合soap请求规范的XML String,如下:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">   <soapenv:Header>   </soapenv:Header>   <
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值