gpt4 book ai didi

java - 将 cookie 注入(inject) WebView 不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 13:38:20 26 4
gpt4 key购买 nike

我在将 cookie 注入(inject) login.php 页面时遇到了一些问题。这是代码:

LinearLayout lLayout = (LinearLayout)findViewById(R.id.linearlayoutIdLogin);
lLayout.setVisibility(View.GONE); //make my standard layout inivisible
LinearLayout lWeb = (LinearLayout)findViewById(R.id.webviewId);
lWeb.setVisibility(View.VISIBLE); //make my webview visible
WebView browse = (WebView)findViewById(R.id.webViewBrowse);

上面的代码是正确的。我加载了我的 WebView,但页面显示我需要登录。

这是对我不起作用的 cookie 注入(inject)。

Cookie setcookie = cookie.get(1);
Cookie othercookie = cookie.get(0);
/* I assign my two cookies from a List<Cookie>. cookie.get()
brings the element I need. The cookies overall contains two fields. Therefore
the get 1 and get 0. All this works, I have tested to make a Toast to
print out the cookies */

//Here it must be anything I'm doing wrong?
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.setCookie("http://www.thedomain.com", setcookie.getValue());

browse.setWebViewClient(new WebViewClient(){ });
browse.loadUrl("mypagewhenloggedin.php");

有什么想法吗?已经坚持了几个小时。提前致谢!

编辑代码:忘了说我也添加了这个 cookie。

cookieManager.setCookie("http://www.thedomain.com", othercookie.getValue());

最佳答案

Cookie 上使用 getDomain(),而不是假定域是 "http://www.thedomain.com"。此外,考虑使用 Wireshark 或其他工具来检查 HTTP 请求,以查看与正常工作的浏览器请求相比可能存在格式错误的内容。

关于java - 将 cookie 注入(inject) WebView 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3719544/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com