webservice的基础也是http协议,webservice服务器端根据http请求过来的soap消息,解析此soap消息,完成webservice的调用。那么是不是通过HttpClient也可以调用webservice呢?
HttpClient hc = new HttpClient();
PostMethod pm = new PostMethod("http://localhost:8080/wstest/services/helloWorld");
pm.setRequestBody(sb.toString());       
hc.executeMethod(pm);
System.out.println(pm.getResponseBodyAsString());
但是这样调,根据就调不通。
通过HttpClient能不能完成webservice的调用,知道的大哥出来说说,谢谢啦。

解决方案 »

  1.   

    没必要用httpclient直接URL类就可以了
    URL url = new URL("http://localhost:8080/wstest/services/helloWorld");
     InputStream  inputStream = url.openStream();接下就可以从inputStream 把xml读出来了
      

  2.   

    webservice也是基于HTTP协议的,我只是好奇调用webservice时,发送的http请求和普通的http请求有什么不同,道理上通过HttpClient也是可以调用webservice的?
      

  3.   

    应该是可以调用的,只不过这个httpclient也是一个封装的jar,谁知道它在里面干什么了
      

  4.   

    Client c=new Client(new URL   ("http://localhost:8080/wstest/services/helloWorld"));
     Object[] o=c.invoke("qqCheckOnline", new String[]{"531086641","591284436"});
      

  5.   

    可以调的通.不过你的请求漏写了吧.
    POST /WebServices/WeatherWebService.asmx HTTP/1.1
    Host: www.webxml.com.cn
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://WebXml.com.cn/getSupportCity"
    这是一个webservice的请求头.其中需要一个SOAPAction请求头.你的请求没有该信息,所以失败.
      

  6.   

    请问这个请求头是拼都报文中,还是通过PostMethod设置一下,我下面这样设置不起作用,还是调用不到相应的方法
    pm.addRequestHeader("SOAPAction", "http://WebXml.com.cn/getSupportCity");
      

  7.   


    一般的http请求的请求体是空的(POST例外), 而Webservice的http请求体是soap请求报文