开发者

Android - Acessing WebService with XPath

开发者 https://www.devze.com 2023-04-13 05:38 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号