【发布时间】:2020-03-30 14:09:48
【问题描述】:
我正在尝试在 Oreo 上使用 CookieManager 设置 cookie(https://developer.android.com/reference/android/webkit/CookieManager#setCookie(java.lang.String,%20java.lang.String,%20android.webkit.ValueCallback%3Cjava.lang.Boolean%3E) 及以上用于 Webview,
它使用10.0.2.2:8080从我的笔记本电脑上运行的本地服务器加载(比如说localhost:8080)
众所周知,对于安卓模拟器来说,localhost地址是由10.0.2.2引用的
据我所知,One 可以为 10.0.2.2 设置 cookie
还有没有办法调试cookie设置失败的原因? 我正在通过 chrome 检查器(chrome://inspect)检查 cookie 是否设置
这是用例(react-native,但它在后台使用常规 CookieManager):
import CookieManager from '@react-native-community/cookies';
// Set cookies from a response header
// This allows you to put the full string provided by a server's Set-Cookie
// response header directly into the cookie store.
CookieManager.setFromResponse(
'http://10.0.2.2:8080',
'user_session=abcdefg; path=/; expires=Thu, 1 Jan 2030 00:00:00 -0000; secure; HttpOnly')
.then((res) => {
// `res` will be true or false depending on success.
console.log('CookieManager.setFromResponse =>', res);
});
【问题讨论】:
-
如果你想知道的话,我也在刷新 cookie。 cookie 设置也适用于常规域,以及 cookie 设置适用于我检查的 4.4。
-
如果您使用常规域的 IP,设置 cookie 对您有用吗?
标签: android react-native cookies android-emulator android-webview