zoukankan      html  css  js  c++  java
  • android 取网址的HTML代码

    /**
         * 
         * 
    @param aUrl 网址
         * 
    @param aEncode 编码
         * 
    @return 返回的HTML代码
         * 
    @throws Exception 对外抛出异常
         
    */
        public String getHTML(String aUrl, String aEncode) throws Exception {
            URL url = new URL(aUrl);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setConnectTimeout(5000);
            conn.setRequestMethod("GET");
            if (conn.getResponseCode() == 200){
                InputStream inputStream = conn.getInputStream();                
                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                byte[] buffer = new byte[1024];
                int len = 0;
                while( (len = inputStream.read(buffer)) != -1){
                    outStream.write(buffer, 0, len);
                }
                String htmlStr = new String(outStream.toByteArray(), aEncode);
                inputStream.close();
                outStream.close();
                return htmlStr;
            }
            return null;
        }
  • 相关阅读:
    html5 input type=search
    深入理解html5系列-文本标签
    HTML5里autofocus属性
    sessionStorage和localStorage中 存储
    knockoutjs foreach array绑定 表格 下拉框绑定
    redis’五种格式的存储与展示
    redis与memcache的区别2
    mysql分区及实例演示
    windows下安装redis以及测试
    mysql导入导出sql文件
  • 原文地址:https://www.cnblogs.com/jxgxy/p/2636548.html
Copyright © 2011-2022 走看看