Android WebView加载本地网页cookies无效问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhe_ge_sha_shou/article/details/85634489

今天遇到个坑,特此记录下,用WebView加载assets本地下的网页,发现网页中的cookies失效,不能获取到cookie的值。尝试了以下几种浏览器加载本地的html:

浏览器 加载本地html cookie是否可用
Google Chrome浏览器 不能用
360浏览器 不能用(应该是基于Chrome内核的原因)
Firefox浏览器 能用
Android 不能用
iOS 能用

最后度娘了下,说Chrome浏览器因为安全原因,禁用加载本地网页cookies的使用。What the fuck?,这里也不知道有没有通过其它设置来开启cookies的使用,如果有,麻烦留言告知下,谢谢。
解决方法:

  • 有的说是用WebView的loadDataWithBaseURL方法代替,但我试了不好使,不知道是不是使用的姿式不正确。
  • 后来让网页改成使用本地存储localStorage来代替cookies的使用。

猜你喜欢

转载自blog.csdn.net/zhe_ge_sha_shou/article/details/85634489