标签: android-cookiemanager

在 CookieManager 中 setCookie 后是否需要刷新?

我有一段代码将 okHttp 中的 cookie 写入 CookieManager,如下所示。

@Override
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
    CookieManager webviewCookieManager = CookieManager.getInstance();
    String urlString = url.toString();

    for (Cookie cookie : cookies) {
        webviewCookieManager.setCookie(urlString, cookie.toString());
    }
    webviewCookieManager.flush();
}
Run Code Online (Sandbox Code Playgroud)

我调用flush的 API 如下所示。

/**
 * Ensures all cookies currently accessible through the getCookie API are
 * written to persistent storage.
 * This call will block the caller until it is done and may perform I/O.
 */
public abstract void flush();
Run Code Online (Sandbox Code Playgroud)

但是,即使我删除它,setCookie它本身似乎仍然存在。我还需要吗flush

android webkit android-webview cookiemanager android-cookiemanager

5
推荐指数
0
解决办法
3505
查看次数

Java android - CookieHandler - 关闭应用程序后如何保留cookie?

要在HttpURLConnection中的每个请求之后保留cookie,应该在应用程序上添加CookieHandler:

CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);
Run Code Online (Sandbox Code Playgroud)

但是在应用程序关闭并再次打开时,cookie是空的...那么如何在关闭后保存cookie?

有点像将它们保存在SharedPreferences或文件中,并在打开后将它们取回...

我尝试使用CookieStore保留它们,但这不起作用:...

保存:

Settings.Save(c, TAG, cookieManager.getCookieStore().getCookies().toString());
Run Code Online (Sandbox Code Playgroud)

加载:

String load = Settings.Load(c, TAG);
if (load != null) {
    for (HttpCookie hc : HttpCookie.parse(load)) {
        cookieManager.getCookieStore().add(new URI(Data.domain), hc);
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢..

java android session-cookies cookiestore android-cookiemanager

3
推荐指数
1
解决办法
3377
查看次数

Volley忽略Cookie标头请求

美好的一天!

我的应用程序使用简单的http客户端 - 服务器通信,在客户端与Volley库建立.首先,我启动一个授权请求:

public class AuthenticationRequest extends StringRequest {

    private static final String TAG = AuthenticationRequest.class.getSimpleName();

    private String login;
    private String password;

    public AuthenticationRequest(int method,
                                 String url,
                                 Response.Listener<String> listener,
                                 Response.ErrorListener errorListener) {
        super(method, url, listener, errorListener);
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    protected Map<String, String> getParams() {
        HashMap<String, String> parameters = new HashMap<>();
        parameters.put("login", login);
        parameters.put("password", password);
        return parameters;
    }

    @Override
    protected Response<String> parseNetworkResponse(NetworkResponse response) …
Run Code Online (Sandbox Code Playgroud)

android androidhttpclient android-volley android-cookiemanager

2
推荐指数
1
解决办法
3865
查看次数

我应该如何测试 WebView Android 的 cookie?

我有一个加载给定 URL 的 webview(比如 google.com)。我登录了谷歌,但在关闭 WebView 活动并重新启动一个新活动后,我认为我必须再次登录,但我没有。我还没有使用 CookieManager 设置我的 Cookie。我假设 WebView 默认存储一些 cookie。

所以我的问题是,如何使用给定的 cookie 测试我的 webView.loadURL 是否正常工作?

cookies android android-webview android-cookiemanager

2
推荐指数
1
解决办法
1078
查看次数

如何清理WebView中创建的会话?

我有一个WebView实例,允许用户进行身份验证并访问网络应用程序提供的某些功能。用户完成工作后WebView,出于安全目的,我们需要清理会话。

奇怪的是,下次我打开屏幕时WebView,会话仍然存在,尽管我尝试清理会话,但我可以从上次中断的地方继续。

我尝试做的事情(我实际上运行了调试器以确保调用这些方法):

webView.clearCache(true)
webView.clearFormData()
webView.clearHistory()
webView.clearSslPreferences()
webView.clearMatches()

CookieManager.getInstance().removeAllCookies {
    CookieManager.getInstance().flush()
}
Run Code Online (Sandbox Code Playgroud)

flush()我在的 回调中调用的原因removeAllCookies()是该removeAllCookies()方法是异步的,所以我想也许需要一些时间才能将内存中 cookie 存储的状态与持久存储同步,但这没有帮助。

我对 没有做任何花哨的事情CookieManager,它是操作系统提供的默认设置(Pixel 2 XL 上安装的 Android 9.0)。我有什么遗漏的吗?

session android webview android-cookiemanager

2
推荐指数
1
解决办法
3761
查看次数

AndroidManager 4.1.2上的CookieManager.removeExpiredCookie崩溃

以下代码与Android 4.1.2上包含的线程转储(在Sprint Note II上)崩溃.

CookieManager.getInstance().removeExpiredCookie()
Run Code Online (Sandbox Code Playgroud)

倾倒:

12-12 13:45:35.484    1551-2908/com.example.myapp W/dalvikvm? Invalid indirect reference 0x4276f3d8 in decodeIndirectRef
12-12 13:45:35.484    1551-2908/com.example.myapp E/dalvikvm? VM aborting
12-12 13:45:35.484    1551-2908/com.example.myapp A/libc? Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 2908 (AsyncTask #2)
12-12 13:45:35.584  16476-16476/? I/DEBUG? *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
12-12 13:45:35.584  16476-16476/? I/DEBUG? Build fingerprint: 'samsung/t0ltespr/t0ltespr:4.1.2/JZO54K/L900VPAMC2:user/release-keys'
12-12 13:45:35.584  16476-16476/? I/DEBUG? pid: 1551, tid: 2908, name: AsyncTask #2  >>> com.example.myapp <<<
12-12 13:45:35.584 …
Run Code Online (Sandbox Code Playgroud)

android android-cookiemanager

1
推荐指数
1
解决办法
724
查看次数