我已经使用IIS在本地主机上发布了Restful服务。我可以使用url http://localhost/mobservice/MobSrv.svc从系统上的任何浏览器访问此web服务。
getCityList是此服务中的webGet方法,它返回城市列表。我在Android中使用这个服务。但在我的android程序中,它显示了错误:
java.io.FileNotFoundException:http://10.0.2.2/mobservice/MobSrv.svc/getCityList
我的Android代码就像:
String serviceUrl="http://10.0.2.2/mobservice/MobSrv.svc/getCityList";
URL urlToRequest = new URL(serviceUrl);
urlConnection = (HttpURLConnection)
urlToRequest.openConnection();
int statusCode = urlConnection.getResponseCode();
if (statusCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
// handle unauthorized (if service requires user login)
} else if (statusCode != HttpURLConnection.HTTP_OK) {
// handle any other errors, like 404, 500,..
}
InputStream in = new BufferedInputStream(urlConnection.getInputStream());statusCode返回值404,urlConnection.getInputStream()给出异常java.io.FileNotFoundException,如前所述。
在android中启用了亚行集成。
发布于 2016-12-02 08:31:14
使用ipconfig ( Windows )和ifconfig ( Linux )查找计算机IP地址。它将显示为IPv4地址。
然后在请求URL中使用该IP地址代替10.0.2.2。
https://stackoverflow.com/questions/40926472
复制相似问题