按URL读取rss - java.net.ConnectException:连接超时:connect

时间:2011-03-04 18:24:23

标签: java url rss websphere portlet

你好,我有一个问题,我想通过网址使用rss,我不能这样做。 例如:

System.setProperty("https.proxyHost", "proxy.example.local");
System.setProperty("https.proxyPort", "80");

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();

URL url = new URL("http://pplware.sapo.pt/feed/");  
InputStream stream = connection.getInputStream();
InputStream stream = url.openStream();  
Document doc = docBuilder.parse(stream);    
System.out.println ("Root element of the doc is " + doc.getDocumentElement().getNodeName());

错误:

java.net.ConnectException: Connection timed out: connect

我需要在IBM网站和论坛中进行此搜索的帮助,并且不解决问题。 欢迎 JoãoSousa

1 个答案:

答案 0 :(得分:0)

如果您可以通过浏览器打开http://pplware.sapo.pt/feed/,则不需要前两行:

System.setProperty("https.proxyHost", "proxy.example.local");
System.setProperty("https.proxyPort", "80");

没有proxy.example.local

当然,删除行

InputStream stream = connection.getInputStream();

最终的代码是

    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();

    URL url = new URL("http://pplware.sapo.pt/feed/");
    InputStream stream = url.openStream();
    Document doc = docBuilder.parse(stream);
    System.out.println("Root element of the doc is "
            + doc.getDocumentElement().getNodeName());

它对我有用。