Reputation: 677
I'm making an android application wich uses a web service. To access to it, we use a restAdapter. This is the code:
private String URL_PLACE = "http://myaddresstomywebservice";
public RouteCLlegar(Context ctx) {
restAdapter = new RestAdapter.Builder()
.setEndpoint(URL_PLACE)
.build();
cLlegar = restAdapter.create(CLlegar.class);
}
When we access the web service hosted on the web, it works, but when we use localhost, it doesn't.
private String URL_PLACE = "http://localhost:53285";
public RouteCLlegar(Context ctx) {
restAdapter = new RestAdapter.Builder()
.setEndpoint(URL_PLACE)
.build();
cLlegar = restAdapter.create(CLlegar.class);
}
It gives this error:
24963-25327/ni.femer.busesmg.app I/ERROR﹕ el error java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 53285) after 15000ms: isConnected failed: ECONNREFUSED (Connection refused
How can i access localhost from my rest adapter?
Upvotes: 1
Views: 260
Reputation: 153
I would suspect, localhost is your Android device. If you realy want to access something on localhost, you would have to deploy a http Server in your Android device.
Upvotes: 1
Reputation: 5020
10.0.2.2
instead of localhost
.ipconfig
, should be something like 192.168.1.x
), if it's on the same wireless network with your Android device.Don't forget to specify also a port number.
Upvotes: 1