【发布时间】:2021-04-14 10:41:50
【问题描述】:
我想在我的 android 应用程序中执行 Signout 功能。首先,我使用改造进行登录,现在,我想使用改造注销。我正在传递 Authrazation 令牌,如果我不使用令牌,那么我会在标题中得到这个错误“getting response http/1.1, code=403, message=Forbidden,url=https:/auth/user/logout”。如何使用 Retrofit 进行注销并且我得到响应 http/1.1, code=403, message=Forbidden,url=https://auth/user/logout,即使在传递令牌后,响应正文为空,它的显示。怎么办?
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();
}
}
共享偏好
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();
}
型号
@SerializedName("message")
public String message;
ApiInteraction
@FormUrlEncoded
@POST("auth/user/logout")
Call<LogResponse> signOut(@Field("user_Id") Integer user_id,
@Header("Authorization") String authorization);
【问题讨论】:
-
您能详细说明一下吗?你到底有什么问题?