url = new URL("http://192.168.0.133/list.xml");
httpConn = (HttpURLConnection)url.openConnection();
HttpURLConnection.setFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.setRequestProperty("User-Agent", "Mozilla/4.0(compatible;MSIE 6.0;Windows 2000)");
istream = httpConn.getInputStream();
int responseCode=httpConn.getResponseCode();
if(responseCode==HttpURLConnection.HTTP_OK){
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
article.clear();
Document doc = builder.parse(istream);
NodeList nl = doc.getElementsByTagName("item");
for (int i=0;i<nl.getLength();i++){
article.put(i, doc.getElementsByTagName("url").item(i).getFirstChild().getNodeValue());
String str=doc.getElementsByTagName("url").item(i).getFirstChild().getNodeValue();
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
这里的IP是我局域网的地址,注意不能用127.0.0.1,因为它在模拟器里是指模拟器本身,没有局域网的话也可以用10.0.0.2