在我的
Android维基百科阅读器应用程序中,我正在使用HttpURLConnection下载文章的html,一些用户报告他们无法看到文章,而是看到一些CSS,所以看起来他们的操作符在下载之前以某种方式预处理html,而其他维基百科读者似乎工作正常.
示例网址:http://en.m.wikipedia.org/wiki/Black_Moon_(album)
我的方法:
public static String downloadString(String url) throws Exception { StringBuilder downloadedHtml = new StringBuilder(); HttpURLConnection urlConnection = null; String line = null; BufferedReader rd = null; try { URL targetUrl = new URL(url); urlConnection = (HttpURLConnection) targetUrl.openConnection(); if (url.toLowerCase().contains("/special")) urlConnection.setInstanceFollowRedirects(true); else urlConnection.setInstanceFollowRedirects(false); //read the result from the server rd = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); while ((line = rd.readLine()) != null) downloadedHtml.append(line + '\n'); } catch (Exception e) { AppLog.e("An exception occurred while downloading data.\r\n: " + e); e.printStackTrace(); } finally { if (urlConnection != null) { AppLog.i("Disconnecting the http connection"); urlConnection.disconnect(); } if (rd != null) rd.close(); } return downloadedHtml.toString(); }
我无法重现这个问题,但必须有办法解决这个问题吗?我甚至通过将setInstanceFollowRedirects设置为’false’来禁用重定向,但它没有帮助.
我错过了什么吗?
用户报告的示例:
解决方法
carrier is somehow preprocessing the html before it’s downloaded
a way to get around that?
使用HTTPS阻止操作符重写页面. (没有引用)
Am I missing something?
不是我能看到的