简体   繁体   中英

Android: Retrofit 500 Internal server error

here is my code, the request from postman is ok and everything from server side is ok, but from device I'm getting 500 code internal server error, here is my code, anyone can help me please?!.

Postman Body Postman Header

@FormUrlEncoded
    @POST("api/v1/password/updatePassword")
    Call<ResponseUpdatePassword> updatePassword(@Header("Authorization") String BearerToken, @FieldMap Map<String, String> fieldsMap);
 public MutableLiveData<Response<ResponseUpdatePassword>> updatePassword(String token, Map<String, String> hashMap) {
        webservice.updatePassword(token, hashMap).enqueue(new Callback<ResponseUpdatePassword>() {
            @Override
            public void onResponse(Call<ResponseUpdatePassword> call, Response<ResponseUpdatePassword> response) {
                responseUpdatePassword.postValue(response);
            }

            @Override
            public void onFailure(Call<ResponseUpdatePassword> call, Throwable t) {
                call.cancel();
                Log.d(TAG, "updatePassword:onFailure:" + t.getLocalizedMessage());
                responseRequestFailer.postValue(true);
            }
        });
        return responseUpdatePassword;
    }
public LiveData<Response<ResponseUpdatePassword>> updatePassword(String token, String password, String password_confirmation) {
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("password", password);
        hashMap.put("password_confirmation", password_confirmation);
        return userRepository.updatePassword(token, hashMap);
    }
 forgetPasswordViewModel.updatePassword(token, password, password_confirmation).observe(ForgetPasswordActivity.this, this::getResponseUpdatePassword);
    private void getResponseUpdatePassword(Response<ResponseUpdatePassword> response) {
        endProgressLoadingDialog();
        if (response != null) {
            if (response.body() != null) {
                Toast.makeText(this, "" + response.body().getStatus(), Toast.LENGTH_SHORT).show();
                Shard.lunchLoginActivity(this);
            }
        } else {
            Toast.makeText(this, R.string.error_occurred, Toast.LENGTH_SHORT).show();
        }
    }

how you send token using Bearer and also check in post man are you sending data in body or just parms or try like this one time

@POST("api/v1/password/updatePassword")
Call<ResponseUpdatePassword> updatePassword(@Header("Authorization") String BearerToken,
@Body UpdatePassword updatePassword);

make a class

public class UpdatePassword {  
private String password;
private String password_confirmation;

public UpdatePassword (String password, String password_confirmation) {
    this.password= password;
    this.password_confirmation= password_confirmation;
}

}

and send like this

 UpdatePassword  updatePassword=new UpdatePassword (password,confirmPassword) 
 userRepository.updatePassword(token, updatePassword)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM