[英]error “connection refused” when trying to access to a php page stored on localhost from android app
[英]Trying to access localhost from a Java restAdapter on Android
我正在做一個使用網絡服務的android應用程序。 要訪問它,我們使用restAdapter。 這是代碼:
private String URL_PLACE = "http://myaddresstomywebservice";
public RouteCLlegar(Context ctx) {
restAdapter = new RestAdapter.Builder()
.setEndpoint(URL_PLACE)
.build();
cLlegar = restAdapter.create(CLlegar.class);
}
當我們訪問托管在Web上的Web服務時,它可以工作,但是當使用localhost時,它就不能。
private String URL_PLACE = "http://localhost:53285";
public RouteCLlegar(Context ctx) {
restAdapter = new RestAdapter.Builder()
.setEndpoint(URL_PLACE)
.build();
cLlegar = restAdapter.create(CLlegar.class);
}
它給出了這個錯誤:
24963-25327 / ni.femer.busesmg.app I / ERROR:錯誤java.net.ConnectException:15000毫秒后無法連接到localhost / 127.0.0.1(端口53285):isConnected失敗:ECONNREFUSED(連接被拒絕
我如何從我的rest適配器訪問localhost?
我懷疑,本地主機是您的Android設備。 如果您確實想訪問localhost上的內容,則必須在Android設備中部署http服務器。
10.0.2.2
代替localhost
。 ipconfig
檢查,應該類似於192.168.1.x
)。 不要忘記還要指定一個端口號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.