从资产目录中的HTML文件设置Android Webview cookie [英] Setting Android Webview cookies from HTML file in assets directory

查看:230
本文介绍了从资产目录中的HTML文件设置Android Webview cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在webview中使用javascript设置cookie。 webview从本地资产目录加载,如此(其中page是一个字符串,如index.html)

I'm trying to set a cookie using javascript inside a webview. The webview is loaded from the local assets directory like so (where page is a string such as "index.html")

engine.loadUrl("file:///android_asset/" + page);

我发现从网上加载完全相同的文件时(即 http://www.domain.com/index.html )然后,同一文件可以按预期设置cookie。

I have found when the exact same file is loaded from the web (i.e. http://www.domain.com/index.html) then same file can set the cookie as expected.

较早版本的android确实允许在本地文件上创建cookie,但较新版本不允许。我测试了这个,它适用于三星Galaxy Ace,HTC Desire Z和较低SDK的eclipse模拟器,但不适用于三星SIII或三星Tab 10.1。

Older versions of android do allow the creation of cookies on local files, but newer versions do not. I have tested this and it works on Samsung Galaxy Ace, HTC Desire Z and eclipse emulators of lower SDK, but does not work on Samsung SIII nor Samsung Tab 10.1.

I我需要设置一个cookie,以便在我的网页浏览中的页面之间传输数据;保存搜索结果以重新显示。

I need to set a cookie in order to carry data between pages in my webview; saving search results to be re-displayed.

如果有人知道任何方法/黑客来解决这些本地文件问题,我真的很感激它。我已经在这里待了大约8个星期了。我问了一个类似的问题,可能有助于进一步阅读,但问题现在已经确定,并且是一个非常不同的问题所以我在这里问这个问题。 Android网页视图Cookie返回null

If anyone knows of any methods/hacks to get around these local file problem I'd really reeeally appreciate it. I've been at this for about 8 weeks now. I asked a simular question which may be helpful for further reading, but the problem has now been identified and is very much a different question so I'm asking this here. Android webview cookie returns null

谢谢。

推荐答案

这是不可能的原因是由于在localhost上实现cookie的安全限制。如果可以设置cookie,那么其他人也可以创建应用程序并阅读您的应用程序cookie。它曾经可以在早期版本的Android上使用,但后来修补了安全漏洞。

The reason this is not possible is down to a security limitation of implementing cookies over localhost. If cookie setting were possible, then it would also be possible for others to create apps and read your apps cookies. It used to be possible on early versions of Android, but the security hole was later patched.

这就是传统网络浏览器存在相同限制的原因。

This is why the same limitation exists on conventional web browsers.

请参阅此相关问题和答案:
Android webview cookie返回null

See this related question and answer: Android webview cookie returns null

这篇关于从资产目录中的HTML文件设置Android Webview cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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