我正在使用Java访问HTTPS站点,该站点以XML格式返回显示.我在URL本身传递登录凭据.这是代码片段:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
requestURL = "https://Administrator:Password@localhost:8443/abcd";
try {
InputStream is = null;
URL url = new URL(requestURL);
InputStream xmlInputStream =new URL(requestURL).openConnection().getInputStream();
byte[] testByteArr = new byte[xmlInputStream.available()];
xmlInputStream.read(testByteArr);
System.out.println(new String(testByteArr));
Document doc = db.parse(xmlInputStream);
System.out.println("DOC="+doc);
} catch (MalformedURLException e) {
}
我正在该程序中创建一个不验证签名/未签名证书的信任管理器.但是,在运行上述程序时,我收到错误服务器返回的HTTP响应代码:401 for URL:https:// Administrator:Password @ localhost:8443/abcd
我可以在浏览器上使用相同的URL,并正确显示xml.请告诉我如何在Java程序中完成这项工作.