【问题标题】:Android - Acessing WebService with XPathAndroid - 使用 XPath 访问 Web 服务
【发布时间】:2011-10-14 14:29:15
【问题描述】:

我有一个应用程序,我需要解析一个 XML。 当我在 Java 项目上这样做时,工作正常。但是,当我尝试在 Android 项目上执行此操作时,URL 无法连接,我使用的是 XPath。 代码:

私有静态最终字符串 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 conn = (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!!!
}

【问题讨论】:

  • 你的错误是什么?清单上的权限允许互联网吗?你用的是什么手机、模拟器还是真手机?

标签: android xpath service web


【解决方案1】:

在AndroidManifest.xml 中添加更多uses-permission:INTERNET

另外,finally 肯定每次都会被调用。

【讨论】:

    【解决方案2】:

    我使用的是 localhost WebService,要访问它,需要使用端口 8080。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-27
      相关资源
      最近更新 更多