String proxyHost = "172.16.25.1"; int port = 3128; String soapRequestData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + " <soap:Body>" + " <getWeatherbyCityName xmlns=\"http://WebXml.com.cn/\">" + " <theCityName>长沙</theCityName>" + " </getWeatherbyCityName>" + "</soap:Body>" + "</soap:Envelope>"; //然后定义一个PostMethod,这时需要指定web服务的Url; PostMethod postMethod = new PostMethod("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx"); HostConfiguration vHostConfiguration = new HostConfiguration(); vHostConfiguration.setProxy(proxyHost, port); //然后把Soap请求数据添加到PostMethod中 byte[] b = soapRequestData.getBytes("UTF-8"); InputStream is = new ByteArrayInputStream(b,0,b.length); postMethod.setRequestHeader("Content-Type", "text/xml;charset=UTF-8"); postMethod.setRequestHeader("SOAPAction","http://WebXml.com.cn/getWeatherbyCityName"); RequestEntity re = new InputStreamRequestEntity(is,"UTF-8"); postMethod.setRequestEntity(re); // 最后生成一个HttpClient对象,并发出postMethod请求 HttpClient httpClient = new HttpClient(); int statusCode = httpClient.executeMethod(vHostConfiguration,postMethod); System.out.println("-------调用完成------,状态码:"+statusCode); if(statusCode==200) { InputStream anXml = postMethod.getResponseBodyAsStream(); StringBuffer response = new StringBuffer(); java.io.ByteArrayOutputStream bs = new ByteArrayOutputStream(); java.io.BufferedOutputStream out = new BufferedOutputStream(bs); byte[] c= new byte[1024]; int len = 0; while ((len = anXml.read(c))>=0) { out.write(c, 0, len); } out.flush(); anXml.close(); System.out.println(bs.toString(postMethod.getRequestCharSet())); } System.exit(0);
详细解决方案
Webservice调用札记,获取天气情况
热度:81 发布时间:2012-08-10 12:19:33.0
相关解决方案
- java webservice 客户端调用服务器端同时发出多条请求~求高手解决思路
- webservice 赋值有关问题
- cxf webservice 返回json字符串时,数值型的字符串双引号不见了
- webservice…解决方法
- 高手~J2ME客户端,AXIS支撑的TOMCAT WEBSERVICE,两点间可以实现图片和文本数据的户传吗?特别是WEBSERVICE 端传给J2ME端
- webservice 开发方式解决办法
- 软体与其它(多)系统做接口,如何样做好些?webservice
- vc能不能调用c# webservice 的list范型,该怎么处理
- WebService QQ群:11583757 诚邀加盟,该怎么处理
- webservice The operation timed out,该怎么处理
- webservice x相关
- .net 的 webservice 的传入参数加密有关问题求解
- ASP.NET+容易三层架构+WebService+JS
- webservice 同一浏览器跨域调用session的有关问题
- ASP.NET 调用JAVA webservice,该如何处理
- Webservice 服务引用 session有关问题
- 请问下 WebService 版 API 怎么调用
- asp.net webservice asmx文件有关问题
- webservice 调用有关问题
- 请教为什么使用VS2005+WebService+AJAX在返回数据集的时候无法在客户端得到数据集字段的内容
- 大家给推荐几本学习 webservice 的好书吧 !多谢了
- 急2005 webService 的有关问题
- 2005 webService 的有关问题
- WebService 公布后工作不正常
- :xml webservice ,在调试环境是正确的,可在发布后应用里就不正确,请大侠们帮分析分析
- Webservice 缓存有关问题,
- 数据库 和 webservice 有关问题
- 请教怎么部署.net WebService
- 访问 webservice 之前 判断 webservice是否存在或能否连接上,该如何处理
- webservice,该如何解决