Question

I'm trying to read the BBC Football RSS.

Below is the code I've tried:

        URL url = new URL("http://feeds.bbci.co.uk/sport/0/football/rss.xml");        
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(false);
        XmlPullParser xpp = factory.newPullParser();
        xpp.setInput(url.openConnection().getInputStream(), "UTF_8"); // -- ERROR - Line 21

But I'm getting Connection exception.

Below is the exception in console:

java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.<init>(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at com.testing.code.RssParsing.main(RssParsing.java:21)

Any suggestions?

Was it helpful?

Solution 2

Setting the below property does the trick...

System.setProperty("java.net.useSystemProxies", "true");

OTHER TIPS

I use this code :

URL url = new URL("http://feeds.bbci.co.uk/sport/0/football/rss.xml");
    HttpURLConnection conn = (HttpURLConnection) 
    url.openConnection();
    conn.setReadTimeout(10000);
    conn.setConnectTimeout(15000);
    conn.setRequestMethod("GET");
    conn.setDoInput(true);
    conn.connect();
    InputStream stream = conn.getInputStream();
    xmlFactoryObject = XmlPullParserFactory.newInstance();
    XmlPullParser xpp = xmlFactoryObject.newPullParser();
    xpp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
    xpp.setInput(stream, null);
    stream.close();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top