Retrofit 500 内部服务器错误,邮递员工作
Retrofit 500 Internal Server Error, Postman working
我知道肯定有1000个这样的帖子,但是我到处找错了也没找到,所以我希望你们能看一看,如果你发现我遗漏了什么,请告诉我.
令牌class
public class Token {
public static final String POST = "tokens";
@SerializedName("token")
@Expose
private String token;
@SerializedName("role")
@Expose
private String role;
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}
实体class
public class Entity {
public Entity(){}
private Token mToken;
@SerializedName("email")
@Expose
private String mEmail;
@SerializedName("password")
@Expose
private String mPassword;
public Entity setFirstName(String firstName){return this;}
public Entity setLastName(String lastName){return this;}
public Entity setEmail(String email){
mEmail = email;
return this;
}
public Entity setPassword(String password){
mPassword = password;
return this;
}
public Entity setPasswordConfirmation(String passwordConfirmation){return this;}
public Entity setAddress(String address){return this;}
public Entity setCity(String city){return this;}
public Entity setCountryId(Integer countryId){return this;}
public Entity setToken(Token token){
mToken = token;
return this;
}
public String getEmail(){ return mEmail; }
public String getPassword(){ return mPassword; }
public Token getToken(Token token){ return mToken; }
}
API服务
@POST(Token.POST)
Observable<Token> loginEntity(@Body Entity entity);
API 来电
Observable<Token> loginEntityCall = RestClient.getInstance().service.loginEntity(loginEntity);
OkHttp 输出什么
--> POST http://randomapi/api/v1/tokens http/1.1
Content-Type: application/json; charset=UTF-8
Content-Length: 55
{"email":"sample.user@example.com","password":"123456"}
--> END POST (55-byte body)
它returns
<-- 500 Internal Server Error
这是复制到postman中的值
postman
所以邮递员给了 OK,我的应用程序给了我 500。我检查了所有值,但找不到错误。 :p
其实我也遇到过同样的事情。在 Postman 中,您发送的是 RAW json,但在 Retrofit 中,默认情况下您不会这样做。基本上,您发送的不是完全相同的东西。将其更改为发送原始 json。参见 this question
我知道肯定有1000个这样的帖子,但是我到处找错了也没找到,所以我希望你们能看一看,如果你发现我遗漏了什么,请告诉我.
令牌class
public class Token {
public static final String POST = "tokens";
@SerializedName("token")
@Expose
private String token;
@SerializedName("role")
@Expose
private String role;
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}
实体class
public class Entity {
public Entity(){}
private Token mToken;
@SerializedName("email")
@Expose
private String mEmail;
@SerializedName("password")
@Expose
private String mPassword;
public Entity setFirstName(String firstName){return this;}
public Entity setLastName(String lastName){return this;}
public Entity setEmail(String email){
mEmail = email;
return this;
}
public Entity setPassword(String password){
mPassword = password;
return this;
}
public Entity setPasswordConfirmation(String passwordConfirmation){return this;}
public Entity setAddress(String address){return this;}
public Entity setCity(String city){return this;}
public Entity setCountryId(Integer countryId){return this;}
public Entity setToken(Token token){
mToken = token;
return this;
}
public String getEmail(){ return mEmail; }
public String getPassword(){ return mPassword; }
public Token getToken(Token token){ return mToken; }
}
API服务
@POST(Token.POST)
Observable<Token> loginEntity(@Body Entity entity);
API 来电
Observable<Token> loginEntityCall = RestClient.getInstance().service.loginEntity(loginEntity);
OkHttp 输出什么
--> POST http://randomapi/api/v1/tokens http/1.1
Content-Type: application/json; charset=UTF-8
Content-Length: 55
{"email":"sample.user@example.com","password":"123456"}
--> END POST (55-byte body)
它returns
<-- 500 Internal Server Error
这是复制到postman中的值
postman
所以邮递员给了 OK,我的应用程序给了我 500。我检查了所有值,但找不到错误。 :p
其实我也遇到过同样的事情。在 Postman 中,您发送的是 RAW json,但在 Retrofit 中,默认情况下您不会这样做。基本上,您发送的不是完全相同的东西。将其更改为发送原始 json。参见 this question