我正在研究Flutter移动应用程序示例。
Flutter / Dart是否有任何支持持久安全cookie的http库。
示例用例(猜测它应该是非常常见的用例):用户登录一次,应用程序应该能够使用安全cookie成功登录,直到会话到期/用户退出。
在Android上,OkHttp支持持久化cookie并在客户端(应用程序)向后端发出请求时发送持久性cookie。
在Flutter中实现这一目标的最佳方式是什么?
由于
答案 0 :(得分:3)
这与颤动无关,它是纯粹的飞镖但是:
对于cookies,有Cookie
类的dart:io
您可以设置boolean secure
属性和boolean httpOnly
。
对于Http连接,您只需使用dart:http' s HttpClient
。
或您可以使用flutter的createHttpClient
方法,这种方法可以通过flutter推荐用于测试目的(模拟);如上所述here
答案 1 :(得分:0)
我已经发布了一个名为requests的小型flutter库,以协助Cookie感知的HTTP请求(在shared_preferences的帮助下)
pubspec.yaml
dependencies:
requests: ^1.0.0
用法:
import 'package:requests/requests.dart';
// ...
// this will persist cookies
await Requests.post("https://example.com/api/v1/login", body: {"username":"...", "password":"..."} );
// this will re-use the persisted cookies
dynamic data = await Requests.get("https://example.com/api/v1/stuff", json: true);