Reputation: 121
On the image you can see my origiginal URL for the RSS (http://www.fyens.dk/rss/sport) is changed to go to the mobile site (http://mobil.fyens.dk/modules/mobile). How can I avoid this? I can't read the RSS feed from the mobile site.
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++) {
The program jumps to a
catch (Exception e) {
e.printStackTrace();
}
when it reaches the line
Document document = db.parse(is);
Upvotes: 0
Views: 71
Reputation: 386
The site is most likely doing a redirection based on User Agent. You want to fool the site with a different user agent string.
Try doing:
conn.setRequestProperty("User-Agent", "The user agent you want to use");
You will want to use a user agent string that corresponds to a desktop browser. Check this list: http://www.useragentstring.com/pages/Chrome/
Upvotes: 1