分享一下我老师大神的人工智能教程!零基础,通俗易懂!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
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> <