Android - RSS reader: URL 强制移动地址
Android - RSS reader: URL forced to mobile address
在图片上你可以看到我的原始 URL 用于 RSS (http://www.fyens.dk/rss/sport) is changed to go to the mobile site (http://mobil.fyens.dk/modules/mobile)。我怎样才能避免这种情况?我无法从移动站点阅读 RSS 提要。
try {
URL url = new URL("http://www.fyens.dk/rss/sport");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream is = conn.getInputStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(is);
Element element = document.getDocumentElement();
NodeList nodeList = element.getElementsByTagName("item");
if (nodeList.getLength() > 0) {
for (int i = 0; i < nodeList.getLength(); i++) {
程序跳转到一个
catch (Exception e) {
e.printStackTrace();
}
到达第
行时
Document document = db.parse(is);
该网站很可能正在根据用户代理进行重定向。你想用不同的用户代理字符串来欺骗网站。
尝试做:
conn.setRequestProperty("User-Agent", "The user agent you want to use");
您需要使用与桌面浏览器相对应的用户代理字符串。检查此列表:http://www.useragentstring.com/pages/Chrome/
在图片上你可以看到我的原始 URL 用于 RSS (http://www.fyens.dk/rss/sport) is changed to go to the mobile site (http://mobil.fyens.dk/modules/mobile)。我怎样才能避免这种情况?我无法从移动站点阅读 RSS 提要。
try {
URL url = new URL("http://www.fyens.dk/rss/sport");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream is = conn.getInputStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(is);
Element element = document.getDocumentElement();
NodeList nodeList = element.getElementsByTagName("item");
if (nodeList.getLength() > 0) {
for (int i = 0; i < nodeList.getLength(); i++) {
程序跳转到一个
catch (Exception e) {
e.printStackTrace();
}
到达第
行时Document document = db.parse(is);
该网站很可能正在根据用户代理进行重定向。你想用不同的用户代理字符串来欺骗网站。
尝试做:
conn.setRequestProperty("User-Agent", "The user agent you want to use");
您需要使用与桌面浏览器相对应的用户代理字符串。检查此列表:http://www.useragentstring.com/pages/Chrome/