我正在尝试使用排球库做GET请求(StringRequest)。该文件在我的wamp服务器(txt文件)上。我不断收到与我的IP地址和本地主机和10.0.2.2的连接失败。Android Studio服务器连接失败

有2个错误:

与本地主机和10.0.2.2

java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 80) after 2500ms: isConnected failed: ECONNREFUSED (Connection refused)

我IP地址:

java.net.ConnectException: failed to connect to /myIP (port 80) after 5000ms: isConnected failed: EHOSTUNREACH (No route to host)

我给的权限对androidmanifest

这里访问互联网是我的代码:

public void volleyTest(Context ctx) {

RequestQueue queue = Volley.newRequestQueue(ctx);

String url ="http://localhost/file.txt";

StringRequest stringRequest = new StringRequest(Request.Method.GET, url,

new Response.Listener() {

@Override

public void onResponse(String response) {

Log.i("debug","Response is: "+ response.substring(0,500));

}

}, new Response.ErrorListener() {

@Override

public void onErrorResponse(VolleyError error) {

Log.i("debug",error.getMessage());

}

});

queue.add(stringRequest);

}

2017-04-13

OrsCrous

+0

首先尝试在打开你的网址浏览器在设备上看到它的作品。 –

+0

我可以从设备上的浏览器(使用我的IP地址)读取txt文件,但我仍然无法使用Volley打开它 –

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐