dongpian4954 2014-12-18 18:06
浏览 36
已采纳

在Yii中验证来自android的用户

I've this android app from which users can signin and signup to Yii
the signin and signup works fine but when I'm sending other requests like editing Posts and other things, Yii doesn't remember the user, like the user never signed in.
now what information I need to save in the app and send with each request so that Yii know this user has signed in before.
this is the information that I send with my signin request:

ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
nameValuePair.add(new BasicNameValuePair("email", signinEmail.getText().toString()));
nameValuePair.add(new BasicNameValuePair("password", signinPassword.getText().toString()));
HttpRequest siginRequest = new HttpRequest();
JSONObject signinResult = siginRequest.post("users/signin", nameValuePair);

please help me cause it's driving me crazy :(

  • 写回答

2条回答 默认 最新

  • douchuxun4162 2014-12-18 20:04
    关注

    It seems you're trying to communicate through http, say, port number 80 over the web. Take a look at How to do HTTP authentication in android? that covers one that you wanna do.

    If you insist on using key/value pairs for appending credentials to each http request using SharedPreferences is more organized to meet your purpose. So Once you get these values from the response, store them with:

    SharedPreferences apiVals = getSharedPreferences("credentials", MODE_PRIVATE);
    apivals.edit()
       .putString("authToken", authToken)
       .putString("Session", SessionId)
       .commit();
    

    For retrieving:

    SharedPreferences apiVals = getSharedPreferences("apiVals", MODE_PRIVATE);
    String authToken = apiVals.getString("authToken", null);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)