Android应用中怎么获取网址的HTML代码

  介绍

本篇文章为大家展示了Android应用中怎么获取网址的HTML代码,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

具体方法如下:

/* *   *   * @param aUrl网址   * @param aEncode编码   * @return返回的HTML代码   * @throws异常对外抛出异常   */aUrl getHTML公共字符串(字符串,字符串aEncode){抛出异常   网址URL=new URL (aUrl);   HttpURLConnection康涅狄格州=(HttpURLConnection) url.openConnection ();   conn.setConnectTimeout (5000);   conn.setRequestMethod (“GET");   如果(conn.getResponseCode ()==200) {   InputStream InputStream=conn.getInputStream ();   ByteArrayOutputStream outStream=new ByteArrayOutputStream ();   byte[]新字节缓冲区=[1024];   int len=0;   在((len=read(缓冲))!=1){   outStream。写(缓冲区,0,len);   }   字符串htmlStr=新的字符串(outStream.toByteArray (), aEncode);   inputStream.close ();   outStream.close ();   返回htmlStr;   }   返回null;   }

上述内容就Android应是用中怎么获取网址的HTML代码,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。

Android应用中怎么获取网址的HTML代码