Android - Acessing WebService with XPath
I have a application and I need to parser a XML. When I did this on Java Project, works. But, when I try to do this on the Android Project, the URL can't connect, I'm using XPath. Code:
private static final String STRING_XML = "http://localhost:50645/WebServiceClientes.asmx/ListaReservas";
....
// prepare a URL to the geocoder
URL url = new URL(STRING_XML);
// prepare an HTTP connection to the geocoder
HttpURLConnection co开发者_如何学JAVAnn = (HttpURLConnection) url.openConnection();
Document geocoderResultDocument = null;
try {
// open the connection and get results as InputSource.
conn.connect();
InputSource geocoderResultInputSource = new InputSource(conn.getInputStream());
// read result and parse into XML Document
geocoderResultDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(geocoderResultInputSource);
} finally {
conn.disconnect(); //The debug stops here, so, Disconnect!!!
}
In AndroidManifest.xml
add more uses-permission
: INTERNET
Additionally, finally
is certainly called every time.
I was using a localhost WebService, and to access it, need to use port 8080.
精彩评论