一款非常易用的 Dart Cookie 管理库!
1. 关于
SweetCookieJar 是一个开源的 Dart 库。
使用 SweetCookieJar,您可以轻松管理应用程序中的 cookie。
SweetCookieJar 是一个扩展了官方 Cookie 类功能的库。它还可以与 http 包中的 Responses 一起使用,即使响应头中设置了多个 set-cookie(这是 http 包的一个弱点),SweetCookieJar 也能非常轻松地管理这些 cookie 信息!
在 Dart 中处理响应头中设置的多个 set-cookie 无需复杂的实现。只需将 Responses 传递给 SweetCookieJar 的构造函数即可!
1.1. 简介
1.1.1. 安装库
使用 Dart
dart pub add sweet_cookie_jar
使用 Flutter
flutter pub add sweet_cookie_jar
1.1.2. 导入它
import 'package:sweet_cookie_jar/sweet_cookie_jar.dart';
1.1.3. 使用 SweetCookieJar
void main() {
// The cookie set in the response header
// will be extracted by the constructor process.
final cookieJar = SweetCookieJar.from(response: response);
if (cookieJar.isEmpty) {
// It means that there is no cookie information
// in the response header.
return;
}
// You can find cookie by name easily.
final cookie = cookieJar.find(name: 'AWSALB');
print(cookie.name);
print(cookie.value);
// Also you can get cookie as JSON format.
print(cookie.toJson());
if (cookie.isExpired) {
// Do something when cookie is expired.
return;
}
}
1.2. 许可证
Copyright (c) 2021, Kato Shinya. All rights reserved.
Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
1.3. 更多信息
SweetCookieJar 由 **加藤新也 (Kato Shinya)** 设计和实现。