罗马XmlReader没有阅读https feed

时间:2012-09-24 15:53:10

标签: java rss feed rss-reader rome

我正在尝试阅读https://d3ca01230439ce08d4aab0c61810af23:bla@mycon.mycompany.com/recordings.atom

使用罗马,但它给我错误

   INFO: Illegal access: this web application instance has been stopped already.  Could not load org.bouncycastle.jcajce.provider.symmetric.AES$ECB.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.

   Server returned HTTP response code: 401 for URL: https://d3ca01230439ce08d4aab0c61810af23:bla@mycon.mycompany.com/recordings.atom .

我这样做

    URL url =  new URL("https://d3ca01230439ce08d4aab0c61810af23:bla@mycon.mycompany.com/recordings.atom ");

    try {
    SyndFeedInput input = new SyndFeedInput();

        SyndFeed feed = input.build(new XmlReader(url));

        System.out.println("Feed Author:"+feed.getAuthor());

        for(Object entries: feed.getEntries()){

            SyndEntry entry = (SyndEntry) entries;

            System.out.println("title :"+entry.getTitle());
            System.out.println("description : "+entry.getDescription());

        }


    } catch (IllegalArgumentException | FeedException | IOException e) {
        e.printStackTrace();
    }

我是否需要将用户名密码放在某处?

更新

我已经完成了

  URL url =  new URL("https://d3ca01230439ce08d4aab0c61810af23:bla@mycon.mycompany.com/recordings.atom");

    HttpURLConnection httpcon = (HttpURLConnection)url.openConnection();

    String encoding = new sun.misc.BASE64Encoder().encode("username:pass".getBytes());

    httpcon.setRequestProperty  ("Authorization", "Basic " + encoding);

3 个答案:

答案 0 :(得分:7)

当我从浏览器点击该URL时,它会要求进行基本身份验证。您可以使用ROME执行此操作:

URL feedUrl = new URL(feed)
HttpURLConnection httpcon = (HttpURLConnection)feedUrl.openConnection();
String encoding = new sun.misc.BASE64Encoder().encode("username:password".getBytes());
httpcon.setRequestProperty  ("Authorization", "Basic " + encoding);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(httpcon));

您可能不应该使用sun.misc.BASE64Encoder。而是在某处找到另一个。

来自:http://cephas.net/blog/2005/02/09/retrieving-an-rss-feed-protected-by-basic-authentication-using-rome/

答案 1 :(得分:0)

我发现这在身份验证方面更具弹性,此代码可以使用和不使用身份验证:

URL feedUrl = new URL("http://the.url.to/the/feed");
//URL feedUrl = new URL("http://user:pass@the.url.to/the/feed");

HttpURLConnection connection = (HttpURLConnection) feedUrl.openConnection();
if (feedUrl.getUserInfo() != null) {
    String encoding = new sun.misc.BASE64Encoder().encode(feedUrl.getUserInfo().getBytes());
    connection.setRequestProperty("Authorization", "Basic " + encoding);
}

SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(connection));

答案 2 :(得分:0)

您也可以使用以下代替

String encoding = new sun.misc.BASE64Encoder().encode("username:password".getBytes());

到此:

String BASIC_AUTH = "Basic " + Base64.encodeToString("username:password".getBytes(), Base64.NO_WRAP);