如何在颤振中使用会话用户?

dop*_*eee 5 http dart flutter

我一直在尝试使用户登录并使用 dart 在 flutter 中注册 http。不知何故,我想让用户使用会话或 cookie 留在应用程序中。有人尝试过吗?

Jos*_*ush 3

查看请求

  • 截至目前,它使用共享首选项,这不是存储敏感数据(会话 ID 等)的最佳实践(安全方面)问题#1

pubspec.yaml

dependencies:
  requests: ^1.0.0
Run Code Online (Sandbox Code Playgroud)

用法:

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); 
Run Code Online (Sandbox Code Playgroud)