I am trying to do a GET request (StringRequest) with the Volley library. The file is on my wamp server (txt file). I keep getting a connection fail with my IP adress, and with localhost, and with 10.0.2.2.
There are 2 errors :
- with localhost and 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)
- with my IP adress :
java.net.ConnectException: failed to connect to /myIP (port 80) after 5000ms: isConnected failed: EHOSTUNREACH (No route to host)
I gave permissions to access internet on the androidmanifest
Here is my code :
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<String>() {
@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);
}