Android 更新2-请求始终为状态404,响应为空

Android 更新2-请求始终为状态404,响应为空,android,retrofit2,Android,Retrofit2,我看到了其他3篇关于这个的SO帖子,但是解决方案不起作用。每个端点返回为状态代码404,响应在第2段中为空。这是我的改装实施: 改装服务: //code setup for HTTP client for Retrofit goes here ...... ...... public static void initRetrofit() { builder = new Retrofit.Builder()

我看到了其他3篇关于这个的SO帖子,但是解决方案不起作用。每个端点返回为
状态代码404
,响应在第2段中为空。这是我的改装实施:

改装服务:

//code setup for HTTP client for Retrofit goes here
......
......
public static void initRetrofit() {
        builder =
                new Retrofit.Builder()
                        .baseUrl(BuildConfig.BASE_URL)
          .addConverterFactory(GsonConverterFactory.create(initGson()));
}
public interface APIServices {

    @POST("api/users/register.json")
    Call<HttpResponse<Auth>> register(@Body RegisterData data);

}
BuildConfig

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField "String", "BASE_URL", "\"http://MY_SERVICE.azurewebsites.net\""
        }
        debug {
            versionNameSuffix ".staging"
            buildConfigField "String", "BASE_URL", "\"http://MY_SERVICE.azurewebsites.net\""
        }
}
端点:

//code setup for HTTP client for Retrofit goes here
......
......
public static void initRetrofit() {
        builder =
                new Retrofit.Builder()
                        .baseUrl(BuildConfig.BASE_URL)
          .addConverterFactory(GsonConverterFactory.create(initGson()));
}
public interface APIServices {

    @POST("api/users/register.json")
    Call<HttpResponse<Auth>> register(@Body RegisterData data);

}
公共接口服务{
@POST(“api/users/register.json”)
调用寄存器(@Body RegisterData data);
}

我做错了什么?其他SO线程建议从
/api/users/register.json
中删除
/api
/
,我这样做了,但响应中没有任何更改。

您没有为
改造对象设置HTTP客户端。为此,请尝试使用
OkHttpClient

public static void initRetrofit() {
    OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(Config.HTTP_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS)
                .readTimeout(Config.HTTP_READ_TIMEOUT, TimeUnit.MILLISECONDS)
                .writeTimeout(Config.HTTP_READ_TIMEOUT, TimeUnit.MILLISECONDS)
                .build();

        builder =
                new Retrofit.Builder()
                        .baseUrl(BuildConfig.BASE_URL)
                        .client(client)
          .addConverterFactory(GsonConverterFactory.create(initGson()));
}

另外,请检查您的API地址-尝试使用一些服务(例如邮递员):输入您的地址(从您的代码中,它是:“”)

2基本url应以尾部斜杠结尾。尝试添加它:

buildConfigField "String", "BASE_URL", "\"http://MY_SERVICE.azurewebsites.net/\""

这些都已经设置好了,我没有在答案中包括这些。很抱歉,我没有提到:DSo向基本url添加
/
,并从
/api/users
端点删除
/
?是的,这是惯例