读书人

xml解析有关问题需要输入用户名以及

发布时间: 2012-04-28 11:49:53 作者: rapoo

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错误”,我想是如何在代码里实现用户的登录,后在解析?

Java code
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){}



[解决办法]
网址: http://xml2.weather.gov.hk/V2/bulletins/CurrentWeather_iso-8859-1.xml
这个网址打开是需要输入用户名密码的:打开环境:Safari

demo网址: http://demo.xml.weather.gov.hk/V2/bulletins/CurrentWeather_iso-8859-1.xml.1
这个网址打开不需要输入用户名与密码。

读书人网 >Java Web开发

热点推荐