我知道必须有像这样的1000个帖子,但是我到处找不到它的错误,所以我希望你们看看并告诉我你是否注意到我错过的东西
令牌类
Table_Policy_Premium
实体类
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;
}
}
APIService
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);
OkHttp输出
- &GT;发布http://randomapi/api/v1/tokens http / 1.1
Content-Type:application / json;字符集= UTF-8
内容长度:55
{&#34;电子邮件&#34;:&#34; sample.user@example.com",&#34;密码&#34;:&#34; 123456&#34;}
- &GT; END POST(55字节的正文)
返回
&lt; - 500内部服务器错误
这是复制到邮递员的值
所以邮递员给了好,我的应用程序给了我500.我检查了所有的值,我找不到错误。 :P
答案 0 :(得分:0)
我实际上发生了同样的事情。在邮递员中你发送RAW json,但是使用Retrofit你默认不这样做。基本上,你并没有发送完全相同的东西。改变它发送原始的json。见this question