我正在尝试使用翻新2来使用Rest API,我已经能够使用某些终结点,但是注册终结点始终返回http 500错误代码,但在与邮递员进行测试时可以正常工作。
  @POST("auth/signup/") Call<SignUpResponce> addUser(@Body SignUpCreds signUpCreds);

这是注册凭证

public class SignUpCreds {
@SerializedName("username")
@Expose
private String username;
@SerializedName("email")
@Expose
private String email;
@SerializedName("password")
@Expose
private String password;


public SignUpCreds(String username, String email, String password) {
    this.username = username;
    this.email = email;
    this.password = password;
}


}

这是注册回复

public class SignUpResponce {
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("username")
@Expose
private String username;
@SerializedName("email")
@Expose
private String email;
@SerializedName("password")
@Expose
private String password;
@SerializedName("dateRegistered")
@Expose
private Integer dateRegistered;

public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public Integer getDateRegistered() {
    return dateRegistered;
}

public void setDateRegistered(Integer dateRegistered) {
    this.dateRegistered = dateRegistered;
}


}

邮递员中的Json对象

{
"username": "doe2jane",
"email": "[email protected]",
"password": "janedoe"


}

杰森邮递员的回应

{
"id": 7,
"username": "doe2jane",
"email": "[email protected]",
"password": "janedoe",
"dateRegistered": 1499870604166


}

我的signUpCred

SignUpCreds creds = new SignUpCreds(username, email, password);

改造类别:

public class AuthUtil {
private static Retrofit sRetrofit = null;

public static Retrofit getRetrofit(String url){
    Gson gson = new GsonBuilder()
            .setLenient()
            .create();
    if (sRetrofit == null){
        sRetrofit  = new Retrofit.Builder()
                .baseUrl(url)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();
    }
    return sRetrofit;
}


}

邮递员屏幕:https://ibb.co/gNwrQF

最佳答案

首先,请记录错误日志。

500内部服务器错误仅表示服务器中引发了某些异常,并且请求未按预期完成。所以我想这可能是一些空指针异常,原因可能是无效的JSON或您不确定的代码逻辑。

08-05 12:36