I would like to do Signout function in my android application. First, I use retrofit to do login and now, I want to logout using retrofit.I am passing Authrazation Token, in header if i don't use Token in then i will get This error "getting response http/1.1, code=403, message=Forbidden,url=https:/auth/user/logout". How to do Logout using Retrofit and Also i having getting response http/1.1, code=403, message=Forbidden,url=https://auth/user/logout,even after passing token, Response body getting null,its showing. What to do?
Postman Header File
ProfileFregment
signout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SessionMaintain.init(getActivity());
//read string in shared preference.
String token = SessionMaintain.read(SessionMaintain.TOKEN_USER, null);
Integer userId = SessionMaintain.read(SessionMaintain.USER_ID, 0);
logout(userId,token);
}
});
}
private void logout(Integer userId,String authorization) {
ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
Call<LogResponse> logoutCall = apiInterface.signOut(userId,authorization);
logoutCall.enqueue(new Callback<LogResponse>() {
@Override
public void onResponse(Call<LogResponse> call, Response<LogResponse> response) {
Log.d("LogResponse",response.toString());
if(response.isSuccessful()){
LogResponse lresponse = response.body();
lresponse.getMessage();
Log.d("Token","Response"+response.body().getMessage());
Intent i = new Intent(getActivity(), LoginActivity.class);
startActivity(i);
SessionMaintain.clear();
}
}
Shared Preference
public static String read(String key, String defValue) {
return mSharedPref.getString(key, defValue);
}
public static void write(String key, String value) {
SharedPreferences.Editor prefsEditor = mSharedPref.edit();
prefsEditor.putString(key, value);
prefsEditor.commit();
}
public static boolean read(String key, boolean defValue) {
return mSharedPref.getBoolean(key, defValue);
}
public static void write(String key, boolean value) {
SharedPreferences.Editor prefsEditor = mSharedPref.edit();
prefsEditor.putBoolean(key, value);
prefsEditor.commit();
}
Model
@SerializedName("message")
public String message;
ApiInteraction
@FormUrlEncoded
@POST("auth/user/logout")
Call<LogResponse> signOut(@Field("user_Id") Integer user_id,
@Header("Authorization") String authorization);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…