安全なURLの背後にあるXMLファイルにアクセスしようとしています。私は既に持っているXSDバインディングに基づいてURLからファイルをアンマーシャリングしたい。ここに私の方法です。Javaのセキュリティで保護されたURLからXMLをアンマーシャリングする
public void urlTest(String url){
URLConnection connection = null;
JAXBContext jc;
try {
String userPassword = username + ":" + password;
String encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBytes());
URL add = new URL(this.url);
connection = add.openConnection();
connection.setRequestProperty("Authorization", "Basic " + encoding);
connection.connect();
jc = JAXBContext.newInstance("XML");
Unmarshaller u = jc.createUnmarshaller();
Object o = u.unmarshal(connection.getURL());
System.out.println("Complete");
} catch (IOException ex) {
Logger.getLogger(UrlDownload.class.getName()).log(Level.SEVERE, null, ex);
} catch (JAXBException ex) {
Logger.getLogger(UrlDownload.class.getName()).log(Level.SEVERE, null, ex);
}
}
これは401サーバーエラーです。私が渡したユーザー名とパスワードは正しいです。おそらく私は何かを逃しています。
何も心に来ることはありません。私は暗号化されていなければtcpdumpを使って何が出ているのかを調べるでしょう。私は他の人がもっと洗練された何かを提案できると確信しています。 – Anonymoose