我正在使用我的真实电话设备。我的笔记本电脑使用热点连接到了我的手机。我可以在手机屏幕上观看localhost仪表板。
But when i run the app it gives error 404 File Not Found.
用于实例化改造对象的我的改造客户端类:
public class RetrofitClient {
public static final String BASE_URL = "http://192.168.43.170/";
public static RetrofitClient mInstance ;
public Retrofit retrofit;
private RetrofitClient() {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
public static synchronized RetrofitClient getInstance(){
if( mInstance == null){
mInstance = new RetrofitClient();
}
return mInstance;
}
public APIs getApi(){
return retrofit.create(APIs.class);
}
}
==========================================================================
API Interface :
public interface APIs {
@GET("testApi/product/read.php")
Call<loginModelClass> getUsers();
}
答案 0 :(得分:0)
在您的API界面中执行以下操作:
@FormUrlEncoded
@GET("testApi/product/read.php")
Call<loginModelClass> getUsers();
答案 1 :(得分:0)
您需要考虑某些事项。
您要在其中提供API数据的笔记本电脑/ PC /服务器的IP地址。就您而言,它看起来是正确的。我认为您使用的是正确的IP地址。
确保您要访问的URL正确。要测试它,只需打开任何Web浏览器或REST API测试客户端(如Postman)。并尝试访问URL http://192.168.43.170/testApi/product/read.php
。如果返回正确的数据,就可以了。