Rome XmlReader не читает канал https

Я пытаюсь прочитать https://d3ca01230439ce08d4aab0c61810af23:[email protected]/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:[email protected]/recordings.atom .

я делаю это

    URL url =  new URL("https://d3ca01230439ce08d4aab0c61810af23:[email protected]/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:[email protected]/recordings.atom");

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

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

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

person Harry    schedule 24.09.2012    source источник


Ответы (3)


Когда я нажимаю этот 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/

person David Tinker    schedule 24.09.2012
comment
Привет, Дэвид. Спасибо за ваш ответ. Я пробовал выше, но все равно получаю, что сервер возвращает код ответа HTTP: 401 для URL: d3ca01230439ce08d4aab0c61810af23:[email protected]/ ошибка. Я не понял, что вы имеете в виду, вероятно, не следует использовать sun.misc.BASE64Encoder - person Harry; 25.09.2012

Я нахожу это немного более гибким, когда дело доходит до аутентификации, этот код работает с аутентификацией и без нее:

URL feedUrl = new URL("http://the.url.to/the/feed");
//URL feedUrl = new URL("http://user:[email protected]/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));
person javabeangrinder    schedule 10.07.2014

Вы также можете использовать следующее вместо

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

к этому:

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