我試圖做一個職位與翻新檢查是否有一些數據存在於服務器中。我的問題是,無論如何都要通過onResponse或OnFailure。代碼從未傳入這兩種方法。我在日誌中沒有出現任何錯誤。如果我調試,代碼到此爲止:call.enqueue(新的回調(),並在下一步走法外Post方法與改造永不觸發在OnResponse或在OnFailure
一些幫助將欣賞
代碼:
ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);
Call<User> call = apiService.smsPincodeCheck(getPhoneNuber, email);
call.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
if(response.isSuccess()){
Toast.makeText(RegisterThreeActivity.this, "200", Toast.LENGTH_SHORT).show();
}
if(response.code() == 401){
Toast.makeText(RegisterThreeActivity.this, "401", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<User> call, Throwable t) {
}
});
接口:
@FormUrlEncoded
@POST("api/check")
Call<User> smsPincodeCheck(@Field("email") String email, @Field("phoneNumber") String phoneNumber);
用戶模型:
public class User implements Serializable {
private final static String TAG = "User";
@SerializedName("user")
@Expose
private Long id;
private Long commerceId;
private String email;
private String name;
private String lastname;
private String dni;
private String companyCharge;
.
.
. Getters and setters
JSON:
這是我試圖發送到服務器的JSON:
{
"phoneNumber" : "444444444",
"email" : "[email protected]"
}
編輯1:
Call<ResponseSMS> call = apiService.smsPincodeCheck(getPhoneNuber, email);
call.enqueue(new Callback<ResponseSMS>() {
@Override
public void onResponse(Call<ResponseSMS> call, Response<ResponseSMS> response) {
if(response.isSuccess()){
Toast.makeText(RegisterThreeActivity.this, "200", Toast.LENGTH_SHORT).show();
}
if(response.code() == 401){
Toast.makeText(RegisterThreeActivity.this, "401", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<ResponseSMS> call, Throwable t) {
Toast.makeText(RegisterThreeActivity.this, "Failure", Toast.LENGTH_SHORT).show();
}
});
}
接口:
Call<ResponseSMS> smsPincodeCheck(@Field("email") String email, @Field("phoneNumber") String phoneNumber);
型號:
現在0public class ResponseSMS {
public String response;
public int status;
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}
你說你要發送JSON,但你的Retorift接口描述您要發送的形式 – Divers
您的Web服務調用後,什麼類型的數據要退從服務器?這些數據與'用戶'模型有關嗎? –
我怎樣才能發送與我的界面Json?服務器不返回任何內容。 –