cookie_jar 0.0.8 copy "cookie_jar: ^0.0.8" to clipboard
cookie_jar: ^0.0.8 copied to clipboard

outdated

A cookie manager for http requests in Dart, by which you can deal with the complex cookie policy and persist cookies easily.

example/cookie_jar_example.dart

import 'dart:io';

import 'package:cookie_jar/cookie_jar.dart';

void main() async {
//  final List<Cookie> cookies = <Cookie>[
//    new Cookie('name', 'wendux'),
//    new Cookie('location', 'china'),
//  ];
//  final List<Cookie> cookiesExpired = <Cookie>[
//    new Cookie('name', 'wendux')..maxAge = 1,
//    new Cookie('location', 'china')
//      ..expires = new DateTime.now().add(const Duration(hours: 1)),
//  ];
//  final Directory dir = new Directory('./example/.cookies');
//  await dir.create(recursive: true);
//  final CookieJar cj = new CookieJar();
//  //var cj=new PersistCookieJar('./example/.cookies');
//  cj.saveFromResponse(Uri.parse('https://www.baidu.com/xx'), cookies);
//  List<Cookie> results =
//      cj.loadForRequest(Uri.parse('https://www.baidu.com/xx'));
//  assert(results.length == 2);
//  results = cj.loadForRequest(Uri.parse('https://www.baidu.com/xx/dd'));
//  assert(results.length == 2);
//  results = cj.loadForRequest(Uri.parse('https://www.baidu.com/'));
//  assert(results.isEmpty);
//  cj.saveFromResponse(Uri.parse('https://google.com'), cookiesExpired);
//  results = cj.loadForRequest(Uri.parse('https://google.com'));
//  assert(results.length == 2);
//  await new Future<void>.delayed(const Duration(seconds: 2), () {
//    results = cj.loadForRequest(Uri.parse('https://google.com'));
//    assert(results.length == 1);
//  });

  final PersistCookieJar cookieJar = PersistCookieJar();
  cookieJar.persistSession=true;
  cookieJar.deleteAll();
  cookieJar.saveFromResponse(
    Uri.parse('https://flutter.io/'),
    <Cookie>[
      Cookie('test', 'cookie'),
    ],
  );
}
80
likes
40
pub points
98%
popularity

Publisher

verified publisherflutterchina.club

A cookie manager for http requests in Dart, by which you can deal with the complex cookie policy and persist cookies easily.

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on cookie_jar