Android注解登录失败401未授权

Android Annotations Login Failed 401 Unauthorized

我正在使用 Android 注释来管理我的客户端网络服务通信。

当我尝试使用 AA 登录端点时出现 401 Unauthorized 错误,但是当我使用 Postman 时我可以成功登录到该端点并获得响应。

我的 Rest Client 代码是这样的:

@Rest(rootUrl = NetworkConstants.BASE_URL, converters = {GsonHttpMessageConverter.class, StringHttpMessageConverter.class},
    interceptors = {RestAuthInterceptor.class})
public interface RestClient extends RestClientHeaders, RestClientErrorHandling {

@Post(NetworkConstants.OFFICER_LOGIN)
LoginModel loginOfficer(LoginModel.LoginRequest request);
}

我的登录模型是这样的:

public class LoginModel {

@SerializedName("id")
public String id;

@SerializedName("ttl")
public int ttl;

@SerializedName("userId")
public int userId;

@SerializedName("created")
public Date created;

public static class LoginRequest {
    @SerializedName("email")
    public String email;

    @SerializedName("password")
    public String password;
}
}

而我用的url是这样的:

  public static final String BASE_URL = "https://api.com/api/";


  public static final String LOGIN = "login";

而我使用的拦截器class是这样的:

@EBean(scope = EBean.Scope.Singleton)
public class RestAuthInterceptor implements ClientHttpRequestInterceptor {

@Override
public org.springframework.http.client.ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
    HttpHeaders headers = request.getHeaders();
    HttpAuthentication auth = new HttpBasicAuthentication("emailadress", "password");
    headers.setAuthorization(auth);
    return execution.execute(request, body);

}
}

正如我之前所说,当我在 Postman 上使用这些值时,我得到了成功的响应,但是当我在应用程序中尝试此操作时,我遇到了 401 错误。

我尝试了一些解决方案并尝试在拦截器中添加 BasicHttpAuth 但没有成功,我想知道这是一个常见问题还是 API.

有问题

注意:问题中Interceptor class中的API端点url和header值不是真正的值,为了隐私我已经改变了它们。

感谢您的帮助。

原来我的代码没问题,问题出在 back-end,谢谢