具有基本身份验证的 HTTP 请求
我必须使用HTTP基本身份验证从http服务器下载并解析XML文件。现在我是这样做的:
URL url = new URL("http://SERVER.WITHOUT.AUTHENTICATION/some.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
但是通过这种方式,我无法从具有http身份验证的服务器中获取xml(或者我只是不知道)文档。
如果您能向我展示实现目标的最佳和最简单的方法,我将不胜感激。