0

I have written code to parse Rss, but I have problem with auto redirect to mobile site For Example : my URL is http://danviet.vn/rss/24/thoi-su.rss, but when i parse this URL, i got the error : file not found : http://m.danviet.vn/rss/24/thoi-su.rss

My code for parsing:

try {
    URL url = new URL(link);
    System.out.println(url.getHost());
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser parser = factory.newSAXParser();
    XMLReader reader = parser.getXMLReader();
    RSSHandler handler = new RSSHandler();
    reader.setContentHandler(handler);
    InputSource source = new InputSource(url.openStream());
    reader.parse(source);
    return handler.getItemList();
} catch (MalformedURLException e) {
    e.printStackTrace();
}

1 Answers1

0

You should set a specific User-Agent to prevent mobile redirection (or just prevent this rediction for your RSS feed, server-side).

Check this Set the User-Agent Property for a SAX Parser.

Hartok
  • 2,147
  • 20
  • 37