Drupal的Andr​​oid应用程序登录持久性 [英] Drupal Android App Login Persistence

查看:161
本文介绍了Drupal的Andr​​oid应用程序登录持久性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地安装一个Android应用程序,它记录 - 在我的Drupal的网站。

我的问题是登录的用户会话不会持续很长时间。站点清楚地显示我的用户为登录到网站,但在一个小时内,或因此用户不再显示在网站上为活动的。 (我猜是因为我真的不完全知道这一点。)

任何人都可以提供一个深入了解为什么会这样?

在code是如下:

 受保护的Htt presponse doInBackground(空... PARAMS){
// TODO自动生成方法存根
    HttpClient的HttpClient的=新DefaultHttpClient();
    HttpPost httpPost =新HttpPost(http://mystestsite.com/testpoint/user/login);

        // TODO自动生成方法存根
        尝试{
            名单<的NameValuePair> namevaluepairs中=新的ArrayList<的NameValuePair>();
            nameValuePairs.add(新BasicNameValuePair(密码,客户));
            nameValuePairs.add(新BasicNameValuePair(用户名,客户));
            httpPost.setEntity(新UrlEn codedFormEntity(namevaluepairs中));

            //执行HTTP POST请求
            响应= httpClient.execute(httpPost);

            Log.i(似乎工作,response.toString());
            Log.v(code,httpPost.getRequestLine()的toString()+ - + response.toString());

        }赶上(例外五){
            Log.e(HTTP错误,e.toString());
        }
返回响应;
}
 

解决方案

因此​​,它听起来就像是一个问题,你是如何设置你的Cookie。当我做这种事情我通常只是戳在我的HTTP头,直到它们看起来像头被发送形式的网页浏览器一样。问题是知道的Web浏览器和Android应用程序发送所以这里有什么东西去尝试。

这不一定是code解决您的问题,但可能会有所帮助。

使用查尔斯(伟大的工具) http://www.charlesproxy.com/ 这一点。而且没有我没有对公司有任何联系,它只是一个很好的工具。

还有一个特点查尔斯称为反向代理,基本上它可以让你通过查尔斯反弹流量到你的Drupal服务器和它的流动,并从你的应用程序,你可以检查它。

使用查尔斯,你可以嗅出了什么,从你的浏览器了良好的请求看起来像,然后就可以嗅出了什么,从你的Andr​​oid应用程序的请求的样子。比较两个,你可以看到你的应用程序是非常塑造请求头。

调试阶段是这样的:

一旦你得到了查尔斯设置,打你的Drupal服务器几次,检查请求/响应,你所看到的从浏览器的结构。

然后打你的服务从Android应用程序几次,并注意区别。也许cookie不会经历,也许这是畸形的,也许还有别的关于头。这将让你看到你所需要拍摄的,以获得Drupal的接受请求。

I have successfully setup an Android App which logs-in to my drupal website.

My problem is the logged-in user session does not last very long. The site clearly shows my user as logged-in to the site, but within an hour or so the user is no longer shown as active on the site. (I am guessing because I don't really exactly know it.)

Can anyone offer an insight into why this is happening?

The code is as follows:

protected HttpResponse doInBackground(Void... params) {
// TODO Auto-generated method stub
    HttpClient httpClient   =   new DefaultHttpClient();
    HttpPost httpPost       =   new HttpPost("http://mystestsite.com/testpoint/user/login");

        // TODO Auto-generated method stub
        try{
            List<NameValuePair> nameValuePairs  =   new ArrayList<NameValuePair>();
            nameValuePairs.add( new BasicNameValuePair("password", "guest") );
            nameValuePairs.add( new BasicNameValuePair("username", "guest") );
            httpPost.setEntity( new UrlEncodedFormEntity(nameValuePairs));

            //Execute HTTP post request
            response    =   httpClient.execute(httpPost);

            Log.i("SEEMS TO WORK", response.toString());
            Log.v("CODE", httpPost.getRequestLine().toString() + " - " + response.toString());

        }catch(Exception e){
            Log.e("HTTP ERROR", e.toString());
        }
return response;
}

解决方案

So it sounds like it's an issue with how you're setting your cookies. When I do this kind of thing I usually just poke at my http headers until they look the same as the headers being sent form a web browser. Problem is knowing what the web browser and android app are sending so here's something to try.

This is not necessarily a code solution to your problem, but may be helpful.

Use Charles (great tool) http://www.charlesproxy.com/ for this. And no I don't have any connection to the company, it's just a great tool.

There's a feature in Charles called a reverse proxy and basically it allows you to bounce traffic through Charles to your drupal server and you can inspect it as it flows to and from your app.

Using charles you can sniff what a good request from your web browser looks like and then you can sniff what the requests from your android app look like. Compare the two and you can see where your app is badly shaping the request headers.

The debug phase goes like this:

Once you've got Charles set up, hit your drupal server a couple of times and inspect the structure of the request/response that you're seeing from the browser.

Then hit your service a couple of times from the android app and note the differences. Maybe the cookie isn't going through, maybe it's malformed, maybe there's something else about the headers. This will let you see what you need to shoot for in order to get Drupal to accept the requests.

这篇关于Drupal的Andr​​oid应用程序登录持久性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆