सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
एक डार्ट पैकेज जो HTTP में कुकीज़ का प्रबंधन करता है, जिससे कुकीज़ की नीति और सत्रों के बीच स्थायी भंडारण को आसानी से संभाला जा सकता है। यह HTTP क्लाइंट्स के साथ एकीकृत है ताकि डोमेन और पथ नियमों के आधार पर कुकीज़ को स्वचालित रूप से स्टोर, प्राप्त और भेजा जा सके। ऐसे एप्लिकेशन के लिए उपयुक्त जिन्हें वेब सेवाओं के साथ राज्य-आधारित इंटरैक्शन की आवश्यकता होती है, जैसे लॉगिन सत्र या उपयोगकर्ता प्राथमिकताएं। पैकेज कई प्लेटफॉर्मों का समर्थन करता है जैसे Android, iOS, macOS, Windows और Linux, जिससे कुकीज़ प्रबंधन में क्रॉस-प्लेटफॉर्म सुसंगतता सुनिश्चित होती है।
उपयोग
वेब एपीआई में सत्र कुकीज का प्रबंधन करना
उपयोगकर्ता लॉगिन स्थिति को बनाए रखना
HTTP रिक्वेस्ट में कुकी हैंडलिंग को स्वचालित करना
स्थायी वेब इंटरैक्शन का समर्थन करना
सुरक्षित कुकी संग्रहण सक्षम करें
मुख्य विशेषताएँ
स्वचालित कुकी स्थिरता
प्लेटफॉर्म के अनुकूलता
HTTP क्लाइंट्स के साथ एकीकरण
नीति-आधारित कुकी प्रबंधन
सुरक्षित संग्रहण तंत्र
इनके लिए उपयुक्त
सत्र प्रबंधन की आवश्यकता वाले वेब एपीआई क्लाइंट
लंबे समय तक कुकी स्टोरेज की आवश्यकता वाले अनुप्रयोग
प्रमाणित वेब सेवाओं के निर्माण करने वाले विकासकर्मी
क्रॉस-प्लेटफॉर्म मोबाइल और डेस्कटॉप ऐप्स
जटिल कुकी नीतियों वाले ऐप्स
विचार योग्य बातें
HTTP क्लाइंट उदाहरण के साथ हस्तचालित एकीकरण की आवश्यकता होती है
कस्टम स्टोरेज के लिए अतिरिक्त कॉन्फ़िगरेशन की आवश्यकता हो सकती है
अतिरिक्त सुरक्षा उपायों के बिना उच्च सुरक्षा परिवेशों के लिए अनुपयुक्त
मूलभूत कुकी संचालन तक सीमित
नीचे वाले HTTP क्लाइंट के कार्यान्वयन पर निर्भर करता है
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
CookieJar
A cookie manager for http requests in Dart, help you to deal with the cookie policies and persistence.
Get started
Checkout the Migration Guide for breaking changes between versions.
Add dependency
You can use the command to add dio as a dependency with the latest stable version:
$ dart pub add cookie_jar
Or you can manually add cookie_jar into the dependencies section in your pubspec.yaml:
This class is a wrapper for Cookie class.
Because the Cookie class doesn't support Json serialization,
for the sake of persistence, we use this class instead of it.
CookieJar
CookieJar is a cookie container and manager for HTTP requests.
DefaultCookieJar
DefaultCookieJar is a default cookie manager which implements the standard cookie policy declared in RFC.
It saves the cookies in the memory, all cookies will be cleared after the app exited.
To use it:
final cookieJar = CookieJar();
PersistCookieJar
PersistCookieJar is a cookie manager which implements the standard cookie policy declared in RFC.
PersistCookieJar persists the cookies in files,
so if the application exit, the cookies always exist unless call delete explicitly.
To use it:
// Cookie files will be saved in files in "./cookies/4/"final cookieJar = PersistCookieJar(
ignoreExpires: true, // Save/load even cookies that have expired.
);
Note: When using the [FileStorage] in Flutter apps,
use path_provider to obtain available directories.
Directory tempDir = awaitgetTemporaryDirectory();
final tempPath = tempDir.path;
final cookieJar = PersistCookieJar(
ignoreExpires: true,
storage: FileStorage(tempPath),
);
Storage
You can customize your own storage by extending Storage, see FileStorage for more details.
dio is a powerful HTTP client for Dart/Flutter,
which supports global configuration, interceptors, FormData, request cancellation,
file uploading/downloading, timeout, and custom adapters etc.
dio also supports to manage cookies with cookie_jar
using dio_cookie_manager.
For example:
import'package:dio/dio.dart';
import'package:dio_cookie_manager/dio_cookie_manager.dart';
import'package:cookie_jar/cookie_jar.dart';
voidmain() async {
final dio = Dio();
final cookieJar = CookieJar();
dio.interceptors.add(CookieManager(cookieJar));
await dio.get('https://pub.dev/');
// Print cookiesprint(await cookieJar.loadForRequest(Uri.parse('https://pub.dev/')));
// Another request with the cookie.await dio.get("https://pub.dev/");
}