将 cookie 传递给 Android WebView

发布于 2025-01-07 23:48:28 字数 171 浏览 2 评论 0原文

我有一个网络服务。通常我会使用 HttpURLConnection 进行连接。这是我需要的一个。 连接 HttpURLConnection 并从 HttpURLConnection 获取会话和 cookie 信息并打开 WebView。 简而言之 从应用程序进程内输入是否 android.我想在WebView中进行其余的操作。

I have a web service. Normally I give a connection with HttpURLConnection. Here's one I need.
Connect with HttpURLConnection and get session and cookie information from the HttpURLConnection and open WebView.
in short
Input from within the application process whether android. I want to make the rest of the operations in WebView.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹉夏雨初晴づ 2025-01-14 23:48:29

看一下 CookieSyncManager 类。通过谷歌,我发现了这个:

    CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(mWebView.getContext());
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);
    cookieManager.removeSessionCookie();

    cookieManager.setCookie("http://xx.xxx.xxx.com","mid="+MySession.GetSession().sessionId+" ; Domain=.xxx.com");

    cookieSyncManager.sync();


    String cookie = cookieManager.getCookie("http://xx.xxx.xxx.com");

    Log.d(LOGTAG, "cookie ------>"+cookie);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setWebViewClient(new TuWebViewClient());
    mWebView.loadUrl("http://xx.xx.xxx.com");

Have a look at CookieSyncManager class. With google, I found this:

    CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(mWebView.getContext());
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);
    cookieManager.removeSessionCookie();

    cookieManager.setCookie("http://xx.xxx.xxx.com","mid="+MySession.GetSession().sessionId+" ; Domain=.xxx.com");

    cookieSyncManager.sync();


    String cookie = cookieManager.getCookie("http://xx.xxx.xxx.com");

    Log.d(LOGTAG, "cookie ------>"+cookie);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setWebViewClient(new TuWebViewClient());
    mWebView.loadUrl("http://xx.xx.xxx.com");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文