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;
        }
  • 相关阅读:
    手机端页面自适应解决方案
    每日一算法之拓扑排序
    C++顺序容器类总结
    c++ 运算符优先级
    CUDA获取显卡数据
    第一个CUDA程序
    C++有关类的符号总结
    shell编程的一些例子5
    shell编程的一些例子4
    shell编程的一些例子3
  • 原文地址:https://www.cnblogs.com/jxgxy/p/2636548.html
Copyright © 2011-2022 走看看