获取XML从PHP Web服务的URL采用了android [英] Get xml from a php webservice url using android
问题描述
我想读从服务URL中的XML,我写了code,我的网址是好的,从浏览器中看到的,
I want to read a xml from a service url, I wrote the code, my url is ok, seen from browser,
public String getXML(){
String line = null;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpPost = new HttpGet("http://localhost/simplewebservice/index.php?user=1");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
line = EntityUtils.toString(httpEntity);
} catch (Exception ex) {
Log.d("Error reading xml", ex.toString());
}
return line;
}
但它给了我下面的错误 java.net.SocketException异常:权限被拒绝
。
任何人都可以有这个更好的解决办法?
But it gives me the following error java.net.SocketException: Permission denied
.
Can anyone have a better solution for this?
亲切的问候,
Pritom。
推荐答案
我相信,你使用模拟器。
I am sure that your using emulator.
安卓模拟器是独立的虚拟机本身。如果我们提供本地主机/ 127.0.0.1
作为主机名,则仿真器将尝试在其环境中搜索URL。为了避免这个问题,我们需要提供本地计算机的ip地址。
Andriod emulator is separate virtual machine by itself. If we provide localhost/127.0.0.1
as a hostname, then emulator will try to search url within its environment. To avoid this problem, we need to provide the ipaddress of local machine.
请注意,机器名作为主机名也会给问题。
Pls note that machine name as a hostname will also give problem.
127.0.0.1 refers to localhost in the Emulator, not your machine.
Use 10.0.2.2 to connect to your host machine.
这篇关于获取XML从PHP Web服务的URL采用了android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!