Use Url to receive xml
-
12-10-2019 - |
Question
I want to read xml from url:
URL url = new URL("http://192.168.2.20/test.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
This works. But when I want to read from a url that needs authentication this method fails. So for
url = new URL("http://admin:pass@192.168.2.20/test.xml");
it does not work.
Any ideas?
Solution
Something, like this, may be? http://blogs.deepal.org/2008/01/sending-basic-authentication-using-url.html
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow