搜索了一大圈,各种函数都用上了,各种权限也添加了,可还是报错报错报错~!!搜索了一下错误,终于知道怎么解决了,只想对网上转来转去的编(la)辑(ji)说,麻烦有点技术好吗?
无法获取HTML数据可能为:
- 没有添加网络访问权限权限
- 在主线程中执行
解决方法:
1.添加权限:
1 <uses-permission android:name="android.permission.INTERNET" />
2.新建线程执行:
1 Runnable runnable = new Runnable(){ 2 3 @Override 4 public void run() { 5 HttpClient client = new DefaultHttpClient(); 6 StringBuilder builder = new StringBuilder(); 7 8 HttpGet myget = new HttpGet("http://www.cnblogs.com/ch3rry"); 9 try { 10 HttpResponse response = client.execute(myget); 11 BufferedReader reader = new BufferedReader(new InputStreamReader( 12 response.getEntity().getContent())); 13 for (String s = reader.readLine(); s != null; s = reader.readLine()) { 14 builder.append(s); 15 } 16 System.out.println(builder.toString()); 17 } catch (Exception e) { 18 e.printStackTrace(); 19 } 20 } 21 22 };