react-native fetch() cookie 持久化
react-native fetch() cookie persist
我是 react-native 的新手,也是 javascript 中的 fetch
api。我使用后端验证我的应用程序,在我的 ios 模拟器中刷新几次后,应用程序检查它是否在初始加载时通过后端验证,令我惊讶的是,它是!这引出了一个问题,即 react-native 和 fetch
api?
内部持续存在的位置和内容
谢谢!
React Native 上的 fetch
是在 native-level API 之上实现的,并且 与 Android 上的 whatwg specification and the well-known github polyfill. This means that when the actual HTTP request is made, it's made by the native networking stack on iOS or OkHttp3 略有不同 ,在每种情况下,都是底层 ObjC 或 Java 代码处理和存储 cookie,远离您的 JS 代码。
直到 this commit of Nov 2015, cookies weren't properly persisted on Android at all, but since RN 0.16 they've been supported on both platforms regardless of the credential
setting in your fetch
calls. As a result, session cookies and the like work out-of-the-box, which can be disconcerting if you're not expecting anything to be persisted. If you need to manipulate cookies from your JS, have a look at react-native-cookies,它与基础 cookie 存储交互。
我遇到了同样的问题,最后不得不使用 AsyncStorage 来保存令牌和 cookie,还使用 react-native-cookies 清除所有 cookie。例如:CookieManager.cearAll()
我是 react-native 的新手,也是 javascript 中的 fetch
api。我使用后端验证我的应用程序,在我的 ios 模拟器中刷新几次后,应用程序检查它是否在初始加载时通过后端验证,令我惊讶的是,它是!这引出了一个问题,即 react-native 和 fetch
api?
谢谢!
fetch
是在 native-level API 之上实现的,并且 与 Android 上的 whatwg specification and the well-known github polyfill. This means that when the actual HTTP request is made, it's made by the native networking stack on iOS or OkHttp3 略有不同 ,在每种情况下,都是底层 ObjC 或 Java 代码处理和存储 cookie,远离您的 JS 代码。
直到 this commit of Nov 2015, cookies weren't properly persisted on Android at all, but since RN 0.16 they've been supported on both platforms regardless of the credential
setting in your fetch
calls. As a result, session cookies and the like work out-of-the-box, which can be disconcerting if you're not expecting anything to be persisted. If you need to manipulate cookies from your JS, have a look at react-native-cookies,它与基础 cookie 存储交互。
我遇到了同样的问题,最后不得不使用 AsyncStorage 来保存令牌和 cookie,还使用 react-native-cookies 清除所有 cookie。例如:CookieManager.cearAll()