改装响应:{code = 404,消息=未找到}

时间:2019-08-28 12:25:50

标签: android android-studio retrofit2

我正在使用我的真实电话设备。我的笔记本电脑使用热点连接到了我的手机。我可以在手机屏幕上观看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();
}

2 个答案:

答案 0 :(得分:0)

在您的API界面中执行以下操作:

@FormUrlEncoded
@GET("testApi/product/read.php")
Call<loginModelClass> getUsers();

答案 1 :(得分:0)

您需要考虑某些事项。

  1. 您要在其中提供API数据的笔记本电脑/ PC /服务器的IP地址。就您而言,它看起来是正确的。我认为您使用的是正确的IP地址。

  2. 确保您要访问的URL正确。要测试它,只需打开任何Web浏览器或REST API测试客户端(如Postman)。并尝试访问URL http://192.168.43.170/testApi/product/read.php。如果返回正确的数据,就可以了。

  3. 检查系统防火墙设置。很有可能,防病毒程序正在中断从客户端(Android应用程序)到服务器的请求。有时甚至Windows防火墙也会导致此问题。关闭Windows防火墙设置和防病毒程序(如果有)中的防火墙设置。并测试该应用程序。完成测试后,别忘了再次将其重新打开。