zoukankan      html  css  js  c++  java
  • 使用URLConnection获取页面返回的xml数据

        public static void main(String[] args) throws Exception {
    
            String path="http://flash.weather.com.cn/wmaps/xml/hubei.xml";
            URL url = new URL(path);//获得url对象
            HttpURLConnection conn = (HttpURLConnection)url.openConnection();  //创建URLConnection连接
            conn.setReadTimeout(5*1000);
            conn.setRequestMethod("GET");
            BufferedReader bufr=new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));//设置文件输入流的编码,和url的编码一致
            String lines="";
            String result="";
            while ((lines=bufr.readLine())!=null) {
                result+=lines;
            }
            System.out.println(result);        
        }

    特殊的当请求页面被gzip压缩过之后

        public static void main(String[] args) throws Exception {
    
            String path="http://wthrcdn.etouch.cn/WeatherApi?citykey=101010100";
            URL url = new URL(path);
            HttpURLConnection conn = (HttpURLConnection)url.openConnection();  
            conn.setReadTimeout(5*1000);
            conn.setRequestMethod("GET");
            BufferedReader bufr=new BufferedReader(new InputStreamReader(new GZIPInputStream(conn.getInputStream()),"UTF-8"));//使用GZIPInputStream解压缩
            String lines="";
            String result="";
            while ((lines=bufr.readLine())!=null) {
                result+=lines;
            }
            System.out.println(result);        
        }
  • 相关阅读:
    各种贴图
    d3d11devicecontext
    小记2
    Tom Ryaboi
    Tessellation
    关于图形学
    第一章实验
    控制输入框只接收数字及小数点
    JQuery控制文本框是否可以输入
    SQLSERVER中查询一个存储过程使用到的地方
  • 原文地址:https://www.cnblogs.com/changshuo/p/5561989.html
Copyright © 2011-2022 走看看