在Android Phonegap应用程序中未获取Cookie [英] Not getting cookies in Android Phonegap application

查看:162
本文介绍了在Android Phonegap应用程序中未获取Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android 4.4.2
Cordova 3.4.1
jQuery 2.1.0
jQuery Mobile 1.4.2

我需要将我的登录凭据发布到服务器(在这种情况下是IBM Domino 9.01,但它不相关),服务器用会话cookie

I need to post my login credentials to a server (IBM Domino 9.01 in this case, but it's irrelevant) and the server responds with a session cookie, among other things.

这在iOS上工作得很好,但我没有得到任何cookie,所以在Android上使用我的Cordova / PhoneGap应用程序。我看到这个使用Chrome开发工具。我知道Android获取cookie,因为我已经登录,可以浏览。

This works great on iOS, but I don't get any cookies what so ever using my Cordova/Phonegap app on Android. I see this using Chrome Dev Tools. I know that Android gets the cookie because I'm logged in and can browse around. But it doesn't seem to trickle down to the WebView where my JavaScript code lives.

我已经修改了我的appName.java文件:

I have modified my appName.java file:

import android.os.Bundle;
import android.webkit.CookieManager;
import org.apache.cordova.*;
public class Rooms extends CordovaActivity 
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();
        // Set by <content src="index.html" /> in config.xml

        CookieManager.setAcceptFileSchemeCookies(true); //available in android level 12
        CookieManager.getInstance().setAcceptCookie(true); //available in android level 12
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///android_asset/www/index.html");
    }
}



我不能100%确定这部分:

I'm not 100% sure about this part:

CookieManager.getInstance().setAcceptCookie(true)

它编译并运行正常,但我无法访问任何Cookie。

It compiles and runs fine, but I can't access any cookies.

我需要访问cookies,因为据我所知,没有其他方法可以在IBM Domino服务器上的会话中提取NONCE值。

I need access to the cookies because, to my knowledge, there's no other way to extract the NONCE value in a session on a IBM Domino server.

推荐答案

我不认为这个工作我试过它在我的phonegap android应用程序。最好的解决方案是使用localStorage或sessionStorage。也许你可以尝试使用其他方式发送会话,如使用令牌或通过标头发送...这是我现在做的..
也检查这个

I don't think this works I tried it on my phonegap android application . The Best solution is to use localStorage or sessionStorage. Maybe you can try to use some other means of sending sessions like using tokens or sending them through headers... that's what i'm doing now.. also check this out

在PhoneGap / Cordova 中处理Cookie

Handling cookies in PhoneGap/Cordova

这篇关于在Android Phonegap应用程序中未获取Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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