利用HTTPCLIENT调用WEBSERVICE接口,axis1.4报no SOAPAction header!解决

利用HTTPCLIENT调用WEBSERVICE接口,结果出现报错no SOAPAction header!

百度查了下,说是axis1.4的bug,于是反编译查看了源码,发现需要获取header SOAPAction,于是加了就可以成功了

代码中的1.xml实际上是soap的报文

例如:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservice.autotest.asiainfo.com">
   <soapenv:Header/>
   <soapenv:Body>
      <web:queryUserById>
         <web:userId>1111</web:userId>
      </web:queryUserById>
   </soapenv:Body>
</soapenv:Envelope>

 

java代码如下:

        Map<String,String> map = new HashMap<String,String>();
        try {
            httpClient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://10.7.5.56:1808/AutoTestWeb/services/AutoTestWebservice?wsdl"); //webservice服务地址
            String xml = FileUtils.readFileToString(new File("e:/1.xlml"));//
            String soapRequestData = xml; //soap协议的格式,定义了方法和参数
            HttpEntity re = new StringEntity(soapRequestData, HTTP.UTF_8);
            httppost.setHeader("Content-Type","application/soap+xml; charset=utf-8");
            httppost.setHeader("SOAPAction","application/soap+xml; charset=utf-8");//随便填,必须要有值
            httppost.setEntity(re);
            HttpResponse response = httpClient.execute(httppost); //调用接口
            System.out.println(response.getStatusLine().getStatusCode());
            if(response.getStatusLine().getStatusCode() == 200) {  //调用状态
                String xmlString = EntityUtils.toString(response.getEntity());
                System.out.println("===="+xmlString);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            httpClient.getConnectionManager().shutdown(); //关闭连接
        }
    }
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值