你好,朋友们早安,
我正在为需要功能的应用程序工作login/logout
。在这里我登录成功,之后注销也很完美,但是当我尝试again login
进入给我的应用程序时406 status code
。在这里,我使用sharedpreference
s 作为登录/注销功能。
但是当我restart the application
它随机工作时,意味着它有时可能登录或有时不登录。但是,当close the emulator
再次开始时,它就完美了。
登录.java
请检查
onPostExecute()
以下代码的方法
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
String loginURL = "http://www.cheerfoolz.com/rest/user/login";
strResponse = util.makeWebCall(loginURL, uName, Password);
try {
JSONObject jsonSession = new JSONObject(strResponse);
session = new SessionID();
SessionID.sessionId = jsonSession.getString("sessid");
SessionID.sessionName = jsonSession.getString("session_name");
JSONObject jsonuser=jsonSession.getJSONObject("user");
SessionID.userID = jsonuser.getInt("uid");
} catch (JSONException e1) {
e1.printStackTrace();
}
return null;
}
@Override
public void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
try {
if (strResponse.substring(KEY_SUCCESS) != null) {
txterror.setText("");
SharedPreferences userDetails =getSharedPreferences("userdetails", MODE_PRIVATE);
Editor edit = userDetails.edit();
edit.putString("username", uName);
edit.putString("password", Password);
edit.commit();
} else {
txterror.setText("Username and Password Not valid !!!");
}
} catch (Exception e) {
// TODO: handle exception
}
}
主.java
在主课中,我有一个注销按钮。
case R.id.home_btn_feature_logout:
SessionID.setUserID(0);
SharedPreferences settings = getSharedPreferences("userdetails", MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.remove("username");
editor.remove("password");
editor.clear();
editor.commit();
login.setVisibility(View.VISIBLE);
logout.setVisibility(View.GONE);
break;
在这里我认为会话数据没有正确清除,请让我知道我在哪里做错了。还有另一种登录/注销的解决方案,然后通知我。
谢谢你。