xml解析问题,需要输入用户名以及密码?
要求:访问指定的网址xml,解析并读取里面的(天文台)信息;
网址: http://xml2.weather.gov.hk/V2/bulletins/CurrentWeather_iso-8859-1.xml
demo网址: http://demo.xml.weather.gov.hk/V2/bulletins/CurrentWeather_iso-8859-1.xml.1
现在遇到问题,此网址当用IE去打开时,会弹出对话框需要输入用户名和密码,才能进去;
那么我在用Document解析时,报错了“401错误”,我想是如何在代码里实现用户的登录,后在解析?
try { String url = "http://xml2.weather.gov.hk/V2/bulletins/CurrentWeather_iso-8859-1.xml"; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(url); //报错}catch(Exception e){}