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 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b