加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

WEBService服务

发布时间:2020-12-17 00:05:52 所属栏目:安全 来源:网络整理
导读://获取天气预报 public static void getWeather(String cityName) {? try {? SoapObject rpc =new SoapObject("http://WebXml.com.cn/","getWeatherbyCityName");? System.out.println("rpc"+ rpc);? System.out.println("cityName is "+ cityName);? rpc.ad
//获取天气预报 public static void getWeather(String cityName) {? try {? SoapObject rpc =new SoapObject("http://WebXml.com.cn/","getWeatherbyCityName");? System.out.println("rpc"+ rpc);? System.out.println("cityName is "+ cityName);? rpc.addProperty("theCityName",cityName);? AndroidHttpTransport ht =new AndroidHttpTransport("http://www.webxml.com.cn/webservices/weatherwebservice.asmx");? ht.debug =true;? SoapSerializationEnvelope envelope =new SoapSerializationEnvelope(SoapEnvelope.VER11);? envelope.bodyOut = rpc; envelope.dotNet =true;? envelope.setOutputSoapObject(rpc);? ht.call("http://WebXml.com.cn/getWeatherbyCityName",envelope);? SoapObject result = (SoapObject) envelope.bodyIn;? detail = (SoapObject) result.getProperty("getWeatherbyCityNameResult");? System.out.println("result"+ result);? System.out.println("detail"+ detail);? parseWeather(detail);? return;? } catch (Exception e) {? e.printStackTrace();? }? } ? //解析数据 public static void parseWeather(SoapObject detail){? String date = detail.getProperty(6).toString();? String weatherToday ="今天:"+ date.split("")[0];? weatherToday = weatherToday +"n天气:"+ date.split("")[1];? weatherToday = weatherToday +"n气温:"? + detail.getProperty(5).toString();? weatherToday = weatherToday +"n风力:"? + detail.getProperty(7).toString() +"n";? System.out.println("weatherToday is "+ weatherToday);? }?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读