{"id":3507,"date":"2021-07-16T14:45:28","date_gmt":"2021-07-16T06:45:28","guid":{"rendered":"http:\/\/123.57.164.21\/?p=3507"},"modified":"2021-07-16T14:45:28","modified_gmt":"2021-07-16T06:45:28","slug":"swift-cookie%e5%86%85%e5%ae%b9%e7%9a%84%e8%af%bb%e5%8f%96%e3%80%81%e5%88%a0%e9%99%a4%e3%80%81%e5%86%99%e5%85%a5%ef%bc%88%e9%99%84%ef%bc%9a%e6%89%8b%e5%8a%a8%e6%b8%85%e9%99%a4session%ef%bc%89","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=3507","title":{"rendered":"Swift &#8211; Cookie\u5185\u5bb9\u7684\u8bfb\u53d6\u3001\u5220\u9664\u3001\u5199\u5165\uff08\u9644\uff1a\u624b\u52a8\u6e05\u9664Session\uff09"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">\u4e00\u3001\u57fa\u672c\u6982\u5ff5\u4ecb\u7ecd<\/h5>\n\n\n\n<h5 class=\"wp-block-heading\">1\uff0cCookie \u4ecb\u7ecd<\/h5>\n\n\n\n<p>\uff081\uff09<strong>Cookie\u00a0<\/strong>\u662f\u5728\u00a0<strong>HTTP\u00a0<\/strong>\u534f\u8bae\u4e0b\uff0c\u670d\u52a1\u5668\u6216\u811a\u672c\u53ef\u4ee5\u7ef4\u62a4\u5ba2\u6237\u5de5\u4f5c\u7ad9\u4e0a\u4fe1\u606f\u7684\u4e00\u79cd\u65b9\u5f0f\u3002<strong>Cookie\u00a0<\/strong>\u662f\u7531\u00a0<strong>Web\u00a0<\/strong>\u670d\u52a1\u5668\u4fdd\u5b58\u5728\u7528\u6237\u6d4f\u89c8\u5668\uff08\u5ba2\u6237\u7aef\uff09\u4e0a\u7684\u5c0f\u6587\u672c\u6587\u4ef6\uff0c\u5b83\u53ef\u4ee5\u5305\u542b\u6709\u5173\u7528\u6237\u7684\u4fe1\u606f\u3002<\/p>\n\n\n\n<p><br>\uff082\uff09\u65e0\u8bba\u4f55\u65f6\u7528\u6237\u94fe\u63a5\u5230\u670d\u52a1\u5668\uff0c\u6d4f\u89c8\u5668\u90fd\u4f1a\u628a\u8bf7\u6c42\u7684\u7f51\u5740\u8fde\u540c\u8be5\u00a0<strong>Cookie\u00a0<\/strong>\u4e00\u540c\u63d0\u4ea4\u7ed9\u670d\u52a1\u5668\u3002\u670d\u52a1\u5668\u68c0\u67e5\u8be5\u00a0<strong>Cookie<\/strong>\uff0c\u4ee5\u6b64\u6765\u8fa8\u8ba4\u7528\u6237\u72b6\u6001\u3002<\/p>\n\n\n\n<p>\uff083\uff09\u76ee\u524d\u6709\u4e9b\u00a0<strong>Cookie\u00a0<\/strong>\u662f\u4e34\u65f6\u7684\uff0c\u6709\u4e9b\u5219\u662f\u6301\u7eed\u7684\u3002<\/p>\n\n\n\n<ul><li>\u4e34\u65f6\u7684\u00a0<strong>Cookie\u00a0<\/strong>\u53ea\u5728\u6d4f\u89c8\u5668\u4e0a\u4fdd\u5b58\u4e00\u6bb5\u89c4\u5b9a\u7684\u65f6\u95f4\uff0c\u4e00\u65e6\u8d85\u8fc7\u89c4\u5b9a\u7684\u65f6\u95f4\uff0c\u8be5\u00a0<strong>Cookie\u00a0<\/strong>\u5c31\u4f1a\u88ab\u7cfb\u7edf\u6e05\u9664\u3002<\/li><li>\u6301\u7eed\u7684\u00a0<strong>Cookie\u00a0<\/strong>\u5219\u4fdd\u5b58\u5728\u7528\u6237\u7684\u00a0<strong>Cookie\u00a0<\/strong>\u6587\u4ef6\u4e2d\uff0c\u4e0b\u4e00\u6b21\u7528\u6237\u8fd4\u56de\u65f6\uff0c\u4ecd\u7136\u53ef\u4ee5\u5bf9\u5b83\u8fdb\u884c\u8c03\u7528\u3002<\/li><\/ul>\n\n\n\n<h5 class=\"wp-block-heading\">2\uff0cSession \u4ecb\u7ecd<\/h5>\n\n\n\n<p>\uff081\uff09<strong>Session\u00a0<\/strong>\u662f\u53e6\u4e00\u79cd\u8bb0\u5f55\u5ba2\u6237\u72b6\u6001\u7684\u673a\u5236\uff0c\u4e0d\u540c\u7684\u662f\u00a0<strong>Cookie\u00a0<\/strong>\u4fdd\u5b58\u5728\u5ba2\u6237\u7aef\u6d4f\u89c8\u5668\u4e2d\uff0c\u800c\u00a0<strong>Session\u00a0<\/strong>\u4fdd\u5b58\u5728\u670d\u52a1\u5668\u4e0a\u3002<\/p>\n\n\n\n<p>\uff082\uff09\u5ba2\u6237\u7aef\u6d4f\u89c8\u5668\u8bbf\u95ee\u670d\u52a1\u5668\u7684\u65f6\u5019\uff0c\u670d\u52a1\u5668\u628a\u5ba2\u6237\u7aef\u4fe1\u606f\u4ee5\u67d0\u79cd\u5f62\u5f0f\u8bb0\u5f55\u5728\u670d\u52a1\u5668\u4e0a\u3002\u8fd9\u5c31\u662f\u00a0<strong>Session<\/strong>\u3002<\/p>\n\n\n\n<p>\uff083\uff09\u5b9e\u9645\u4e0a\u5927\u591a\u6570\u7684\u5e94\u7528\u90fd\u662f\u7528\u00a0<strong>Cookie\u00a0<\/strong>\u6765\u5b9e\u73b0\u00a0<strong>Session\u00a0<\/strong>\u8ddf\u8e2a\u7684\u3002\u5373\u7b2c\u4e00\u6b21\u521b\u5efa\u00a0<strong>Session\u00a0<\/strong>\u7684\u65f6\u5019\uff0c\u670d\u52a1\u7aef\u4f1a\u5728\u00a0<strong>HTTP\u00a0<\/strong>\u534f\u8bae\u4e2d\u544a\u8bc9\u5ba2\u6237\u7aef\uff0c\u9700\u8981\u5728\u00a0<strong>Cookie\u00a0<\/strong>\u91cc\u9762\u8bb0\u5f55\u4e00\u4e2a\u00a0<strong>Session ID<\/strong>\uff0c\u4ee5\u540e\u6bcf\u6b21\u8bf7\u6c42\u628a\u8fd9\u4e2a\u4f1a\u8bdd\u00a0<strong>ID\u00a0<\/strong>\u53d1\u9001\u5230\u670d\u52a1\u5668\uff0c\u6211\u5c31\u77e5\u9053\u4f60\u662f\u8c01\u4e86\u3002<\/p>\n\n\n\n<p>\uff084\uff09\u5982\u679c\u5ba2\u6237\u7aef\u7684\u6d4f\u89c8\u5668\u7981\u7528\u4e86\u00a0<strong>Cookie<\/strong>\uff0c\u90a3\u4e48\u901a\u5e38\u4f1a\u4f7f\u7528\u4e00\u79cd\u53eb\u505a\u00a0<strong>URL\u00a0<\/strong>\u91cd\u5199\u7684\u6280\u672f\u6765\u8fdb\u884c\u4f1a\u8bdd\u8ddf\u8e2a\uff0c\u5373\u6bcf\u6b21\u00a0<strong>HTTP\u00a0<\/strong>\u4ea4\u4e92\uff0c<strong>URL\u00a0<\/strong>\u540e\u9762\u90fd\u4f1a\u88ab\u9644\u52a0\u4e0a\u4e00\u4e2a\u8bf8\u5982\u00a0<strong>sid=xxxxx<\/strong>\u00a0\u8fd9\u6837\u7684\u53c2\u6570\uff0c\u670d\u52a1\u7aef\u636e\u6b64\u6765\u8bc6\u522b\u7528\u6237\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">3\uff0ciOS \u7cfb\u7edf\u5bf9 Cookie \u7684\u7ba1\u7406<\/h5>\n\n\n\n<p>\uff081\uff09<strong>iOS\u00a0<\/strong>\u63d0\u4f9b\u4e86\u4e00\u4e2a\u95e8\u7528\u6765\u7ba1\u7406\u00a0<strong>Cookie\u00a0<\/strong>\u6570\u636e\u7684\u7c7b\uff1a<strong>HTTPCookieStorage<\/strong>\uff0c\u800c\u5176\u4e2d\u6bcf\u4e00\u4e2a\u00a0<strong>Cookie\u00a0<\/strong>\u6570\u636e\u53c8\u5bf9\u5e94\u4e00\u4e2a\u00a0<strong>HTTPCookie\u00a0<\/strong>\u7c7b\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p>\uff082\uff09\u6bcf\u4e00\u4e2a\u00a0<strong>HTTPCookie\u00a0<\/strong>\u5bf9\u8c61\u91cc\u9762\u5c01\u88c5\u4e00\u4e2a\u00a0<strong>Cookie\u00a0<\/strong>\u6570\u636e\uff0c\u65b9\u4fbf\u6211\u4eec\u8bfb\u53d6\u00a0<strong>Cookie\u00a0<\/strong>\u5185\u5bb9\u3002<\/p>\n\n\n\n<p>\uff083\uff09\u901a\u5e38\u60c5\u51b5\u4e0b\u6211\u4eec\u53ef\u4ee5\u4e0d\u7528\u7ba1\u00a0<strong>Cookie<\/strong>\uff0c\u5982\u679c\u00a0<strong>Response\u00a0<\/strong>\u4e2d\u5e26\u6709\u00a0<strong>Cookie<\/strong>\uff0c<strong>iOS\u00a0<\/strong>\u4f1a\u81ea\u52a8\u8c03\u7528\u00a0<strong>HTTPCookieStorage<\/strong>\uff0c\u628a\u00a0<strong>Cookie\u00a0<\/strong>\u6570\u636e\u4fdd\u5b58\u4e0b\u6765\u3002\u5f53\u6709\u65b0\u7684\u8bf7\u6c42\u65f6\uff0c<strong>URLRequest\u00a0<\/strong>\u4f1a\u81ea\u52a8\u5e26\u4e0a\u76f8\u5e94\u7684\u00a0<strong>Cookie\u00a0<\/strong>\u6570\u636e\u3002<\/p>\n\n\n\n<p>\uff084\uff09\u8fd9\u4e2a\u673a\u5236\u4e0d\u4ec5\u9002\u7528\u4e8e\u00a0<strong>URLSession<\/strong>\uff0c\u540c\u6837\u9002\u7528\u4e8e\u00a0<strong>SwiftHTTP<\/strong>\u3001<strong>Alamofire\u00a0<\/strong>\u7b49\u7b2c\u4e09\u65b9\u00a0<strong>HTTP\u00a0<\/strong>\u7f51\u7edc\u64cd\u4f5c\u5e93\u3002<\/p>\n\n\n\n<p>\uff085\uff09\u6ce8\u610f\uff1a\u7531\u4e8e<strong>\u00a0iOS<\/strong>\u00a0\u5b89\u5168\u7b56\u7565\uff0c\u4e0d\u540c\u00a0<strong>APP\u00a0<\/strong>\u4e4b\u95f4\u662f\u65e0\u6cd5\u5171\u4eab\u00a0<strong>Cookie\u00a0<\/strong>\u7684\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">4\uff0ciOS \u7cfb\u7edf\u4e2d Cookie \u4fdd\u5b58\u5728\u54ea\u91cc\uff1f<\/h5>\n\n\n\n<p>\u4ece\u6700\u524d\u9762\u00a0<strong>Cookie\u00a0<\/strong>\u7684\u4ecb\u7ecd\u90e8\u5206\u53ef\u4ee5\u5f97\u77e5\uff0c<strong>Cookie\u00a0<\/strong>\u662f\u4f1a\u88ab\u6301\u4e45\u5316\u5230\u6587\u4ef6\u4e2d\u3002\u800c\u00a0<strong>iOS\u00a0<\/strong>\u5e73\u53f0\u4e0b\u7684\u5730\u5740\u662f\u5219\u662f\u6c99\u76d2\u7684\uff1a<strong>\/Library\/Cookies\/******.binarycookies<\/strong><\/p>\n\n\n\n<p>\u6bd4\u5982\u4e0b\u56fe\uff0c\u6211\u7684\u5e94\u7528\u8bbf\u95ee\u4e86\u00a0<a rel=\"noreferrer noopener\" href=\"http:\/\/hangge.com\/\" target=\"_blank\">hangge.com<\/a>\uff0c\u5e76\u4fdd\u5b58\u76f8\u5173\u00a0<strong>Cookie<\/strong>\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/07\/image-74.png\" alt=\"\" class=\"wp-image-3508\" width=\"530\" height=\"201\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-74.png 956w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-74-300x114.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-74-768x292.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-74-830x316.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-74-230x88.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-74-350x133.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-74-480x183.png 480w\" sizes=\"(max-width: 530px) 100vw, 530px\" \/><\/figure><\/div>\n\n\n\n<h5 class=\"wp-block-heading\">\u4e8c\u3001Cookie \u7684\u8bfb\u53d6<\/h5>\n\n\n\n<h5 class=\"wp-block-heading\">1\uff0c\u670d\u52a1\u7aef\u4ee3\u7801\uff08cookie.php\uff09<\/h5>\n\n\n\n<ul><li>\u8bbf\u95ee\u8fd9\u4e2a\u00a0<strong>php\u00a0<\/strong>\u9875\u9762\u540e\u4f1a\u5206\u522b\u8bbe\u7f6e\u4e24\u4e2a\u00a0<strong>cookie\u00a0<\/strong>\u503c\u548c\u4e24\u4e2a\u00a0<strong>session\u00a0<\/strong>\u503c\u3002<\/li><li>\u5176\u4e2d\u00a0<strong>session\u00a0<\/strong>\u867d\u7136\u4fdd\u5b58\u5728\u670d\u52a1\u5668\u4e0a\uff0c\u4f46\u5728\u5ba2\u6237\u7aef\u8fd9\u8fb9\u4ecd\u7136\u9700\u8981\u901a\u8fc7\u00a0<strong>cookie\u00a0<\/strong>\u4fdd\u5b58\u4e2a\u00a0<strong>Session ID<\/strong>\u3002\u6240\u4ee5\u5ba2\u6237\u7aef\u5b9e\u9645\u4e00\u4e2a\u5171\u4f1a\u5b58\u653e\u00a0<strong>3<\/strong>\u00a0\u4e2a<strong>cookie\u00a0<\/strong>\u503c\u3002<\/li><\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?\n\/\/\u8bbe\u7f6eCookie\u503c\uff08\u5168\u7ad9\u6709\u6548\uff0c1\u5c0f\u65f6\u540e\u5931\u6548\uff09\nsetcookie(\"cookie1\",\"111\", time() + 3600, \"\/\");\nsetcookie(\"cookie2\", \"222\", time() + 3600, \"\/\");\n \n\/\/\u8bbe\u7f6eSession\u503c\nsession_start();\n$_SESSION[\"session1\"]=333;\n$_SESSION[\"session2\"]=444;\n?><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">2\uff0c\u6837\u4f8b\u4ee3\u7801\uff08ViewController.swift\uff09<\/h5>\n\n\n\n<p>\u7a0b\u5e8f\u542f\u52a8\u540e\u901a\u8fc7\u00a0<strong>URLSession\u00a0<\/strong>\u8bbf\u95ee\u4e0a\u9762\u7684\u90a3\u4e2a\u00a0<strong>php\u00a0<\/strong>\u9875\u9762\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u4fdd\u5b58\u00a0<strong>Cookie<\/strong>\u3002\u70b9\u51fb\u201c<strong>\u8bfb\u53d6Cookie<\/strong>\u201d\u6309\u94ae\uff0c\u5219\u5c06\u8be5\u57df\u540d\u4e0b\u7684\u6240\u6709\u00a0<strong>Cookie\u00a0<\/strong>\u503c\u6253\u5370\u5230\u63a7\u5236\u53f0\u4e2d\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import UIKit\n \nclass ViewController: UIViewController {\n     \n    override func viewDidLoad() {\n        super.viewDidLoad()\n         \n        \/\/\u521b\u5efaURL\u5bf9\u8c61\n        let urlString = \"http:\/\/www.hangge.com\/cookie.php\"\n        let url = URL(string:urlString)\n        \/\/\u521b\u5efa\u8bf7\u6c42\u5bf9\u8c61\n        let request = URLRequest(url: url!)\n         \n        let session = URLSession.shared\n        let dataTask = session.dataTask(with: request, completionHandler: {\n            (data, response, error) -> Void in\n            print(\"\u8bf7\u6c42\u7ed3\u675f!\")\n        }) as URLSessionTask\n         \n        \/\/\u4f7f\u7528resume\u65b9\u6cd5\u542f\u52a8\u4efb\u52a1\n        dataTask.resume()\n    }\n     \n    @IBAction func loadCookies(_ sender: Any) {\n        let url = URL(string: \"http:\/\/www.hangge.com\")!\n        let cstorage = HTTPCookieStorage.shared\n        if let cookies = cstorage.cookies(for: url) {\n            for cookie:HTTPCookie in cookies {\n                print(\"name\uff1a\\(cookie.name)\", \"value\uff1a\\(cookie.value)\")\n            }\n        }\n    }\n     \n    override func didReceiveMemoryWarning() {\n        super.didReceiveMemoryWarning()\n    }\n}<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/07\/image-75-1024x277.png\" alt=\"\" class=\"wp-image-3509\" width=\"541\" height=\"146\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-75-1024x277.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-75-300x81.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-75-768x208.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-75-830x224.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-75-230x62.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-75-350x95.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-75-480x130.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-75.png 1176w\" sizes=\"(max-width: 541px) 100vw, 541px\" \/><\/figure><\/div>\n\n\n\n<h5 class=\"wp-block-heading\">\u4e09\u3001Cookie \u7684\u7f16\u8f91<\/h5>\n\n\n\n<h5 class=\"wp-block-heading\">1\uff0c\u5220\u9664 Cookie<\/h5>\n\n\n\n<p>\u901a\u8fc7\u00a0<strong>HTTPCookieStorage\u00a0<\/strong>\u7684\u00a0<strong>deleteCookie\u00a0<\/strong>\u6211\u4eec\u53ef\u4ee5\u5220\u9664\u6307\u5b9a\u7684\u00a0<strong>Cookie<\/strong>\uff0c\u5982\u679c\u60f3\u8981\u6e05\u7a7a\u6240\u6709\u7684\u00a0<strong>Cookie\u00a0<\/strong>\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u65b9\u5f0f\u5b9e\u73b0\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">let cstorage = HTTPCookieStorage.shared\nif let cookies = cstorage.cookies(for: url) {\n    for cookie in cookies {\n        cstorage.deleteCookie(cookie)\n    }\n}<\/pre>\n\n\n\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u5bf9\u4e8e\u00a0<strong>Session\u00a0<\/strong>\u6765\u8bf4\uff0c\u5982\u679c\u628a\u5b58\u50a8<strong>\u00a0Session ID\u00a0<\/strong>\u7684\u00a0<strong>Cookie<\/strong>\u00a0\u7ed9\u5220\u9664\u4e86\uff0c\u670d\u52a1\u5668\u81ea\u7136\u4e5f\u627e\u4e0d\u5230\u5bf9\u5e94\u7684\u00a0<strong>session<\/strong>\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">2\uff0c\u521b\u5efa Cookie<\/h5>\n\n\n\n<p>\uff081\uff09\u5728\u00a0<strong>iOS\u00a0<\/strong>\u4e2d\uff0c\u6bcf\u4e2a\u00a0<strong>Cookie\u00a0<\/strong>\u6570\u636e\u90fd\u662f\u4e00\u4e2a\u00a0<strong>HTTPCookie\u00a0<\/strong>\u5bf9\u8c61\u3002\u5ba2\u6237\u7aef\u8fd9\u8fb9\u5982\u679c\u9700\u8981\u624b\u52a8\u8bbe\u7f6e\u4e00\u4e2a\u00a0<strong>Cookie<\/strong>\uff0c\u4e5f\u5c31\u662f\u521b\u5efa\u4e00\u4e2a\u00a0<strong>HTTPCookie\u00a0<\/strong>\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p>\uff082\uff09\u521b\u5efa\u5b8c\u6bd5\u540e\uff0c\u901a\u8fc7\u00a0<strong>HTTPCookieStorage\u00a0<\/strong>\u7684\u00a0<strong>setCookie\u00a0<\/strong>\u65b9\u6cd5\uff0c\u5c31\u53ef\u4ee5\u628a\u00a0<strong>Cookie\u00a0<\/strong>\u4fdd\u5b58\u8d77\u6765\u3002<\/p>\n\n\n\n<ul><li>\u5982\u679c\u539f\u6765\u5b58\u5728\u540c\u540d\u7684\u00a0<strong>Cookie<\/strong>\uff08<strong>name\u00a0<\/strong>\u76f8\u540c\uff09\uff0c\u5219\u8986\u76d6\u3002<\/li><li>\u5982\u679c\u539f\u6765\u4e0d\u5b58\u5728\u8be5\u540d\u5b57\u7684\u7684\u00a0<strong>Cookie<\/strong>\uff0c\u5219\u65b0\u589e\u3002<\/li><\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/\u521b\u5efa\u4e00\u4e2aHTTPCookie\u5bf9\u8c61\nvar props = Dictionary&lt;HTTPCookiePropertyKey, Any>()\nprops[HTTPCookiePropertyKey.name] = \"cookie3\"\nprops[HTTPCookiePropertyKey.value] = \"333\"\nprops[HTTPCookiePropertyKey.path] = \"\/\"\nprops[HTTPCookiePropertyKey.domain] = \"www.hangge.com\"\nlet cookie = HTTPCookie(properties: props)\n \n\/\/\u901a\u8fc7setCookie\u65b9\u6cd5\u628aCookie\u4fdd\u5b58\u8d77\u6765\nlet cstorage = HTTPCookieStorage.shared\ncstorage.setCookie(cookie!)<\/pre>\n\n\n\n<p>\uff083\uff09\u540e\u9762\u5f53\u7a0b\u5e8f\u518d\u53d1\u9001\u8bf7\u6c42\u65f6\uff0c\u5982\u679c\u00a0<strong>URl\u00a0<\/strong>\u6b63\u662f\u521b\u5efa\u00a0<strong>HTTPCookie\u00a0<\/strong>\u65f6\u6307\u5b9a\u7684\u00a0<strong>HTTPCookieDomain\u00a0<\/strong>\u503c\u65f6\uff0c\u5c31\u4f1a\u81ea\u52a8\u53d1\u9001\u8fd9\u4e2a\u00a0<strong>Cookie\u00a0<\/strong>\u4e86\u3002<\/p>\n\n\n\n<p>\uff084\uff09\u5982\u679c\u6ca1\u6709\u8bbe\u7f6e\u00a0<strong>Cookie\u00a0<\/strong>\u5931\u6548\u65f6\u95f4\uff0c\u7a0b\u5e8f\u9000\u51fa\u540e\u8fd9\u4e2a\u00a0<strong>Cookie<\/strong>\u00a0\u662f\u4e0d\u4f1a\u81ea\u52a8\u4fdd\u5b58\u7684\u3002\u5982\u679c\u60f3\u8981\u6301\u4e45\u5316\u00a0<strong>Cookie<\/strong>\uff0c\u7ed9\u5b83\u8bbe\u7f6e\u4e2a\u5931\u6548\u65f6\u95f4\uff0c\u8fd9\u6837\u4e0b\u6b21\u542f\u52a8\u00a0<strong>app\u00a0<\/strong>\u8be5\u00a0<strong>Cookie<\/strong>\u4ecd\u7136\u5b58\u5728\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/90\u5929\u540e\u8fc7\u671f\nprops[HTTPCookiePropertyKey.expires] = Date().addingTimeInterval(3600*24*90)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u57fa\u672c\u6982\u5ff5\u4ecb\u7ecd 1\uff0cCookie \u4ecb\u7ecd \uff081\uff09Cookie\u00a0\u662f\u5728\u00a0HTTP\u00a0\u534f\u8bae\u4e0b\uff0c\u670d\u52a1\u5668\u6216\u811a\u672c\u53ef\u4ee5\u7ef4\u62a4\u5ba2\u6237 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,8],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/3507"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3507"}],"version-history":[{"count":3,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/3507\/revisions"}],"predecessor-version":[{"id":3512,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/3507\/revisions\/3512"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}