{"id":3591,"date":"2023-08-22T22:28:35","date_gmt":"2023-08-22T14:28:35","guid":{"rendered":"https:\/\/www.bytetape.com\/?p=3591"},"modified":"2023-09-01T22:52:07","modified_gmt":"2023-09-01T14:52:07","slug":"%e4%bd%bf%e7%94%a8vba%e4%b8%80%e6%ad%a5%e6%ad%a5%e8%8e%b7%e5%8f%96%e7%bd%91%e7%ab%99cookie%ef%bc%8c%e8%bd%bb%e6%9d%beget%e4%bf%a1%e6%81%af%ef%bc%81","status":"publish","type":"post","link":"https:\/\/www.bytetape.com\/?p=3591","title":{"rendered":"\u4f7f\u7528VBA\u4e00\u6b65\u6b65\u83b7\u53d6\u7f51\u7ad9Cookie\uff0c\u8f7b\u677eget\u4fe1\u606f\uff01"},"content":{"rendered":"\n<p>\u5927\u5bb6\u597d\uff0c\u6b22\u8fce\u6765\u5230\u6211\u7684\u535a\u5ba2\uff01\u4eca\u5929\u6211\u8981\u4e3a\u5927\u5bb6\u5206\u4eab\u4e00\u4e2a\u6709\u8da3\u7684\u6280\u5de7\uff0c\u8ba9\u4f60\u8f7b\u677e\u83b7\u53d6\u7f51\u7ad9\u7684Cookie\u4fe1\u606f\u3002\u6709\u4e86\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u66f4\u65b9\u4fbf\u5730\u83b7\u53d6\u4e00\u4e9b\u7f51\u7ad9\u4e0a\u9690\u85cf\u7684\u4fe1\u606f\uff0c\u4e3a\u4f60\u7684\u6570\u636e\u6536\u96c6\u548c\u5206\u6790\u5de5\u4f5c\u63d0\u4f9b\u4fbf\u5229\u3002\u5e9f\u8bdd\u4e0d\u591a\u8bf4\uff0c\u8ba9\u6211\u4eec\u5f00\u59cb\u5427\uff01<\/p>\n\n\n\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5c06\u5411\u5927\u5bb6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528VBA\u6765\u83b7\u53d6\u7f51\u7ad9\u7684Cookie\u4fe1\u606f\u3002\u9996\u5148\uff0c\u8ba9\u6211\u7ed9\u5927\u5bb6\u5c55\u793a\u4e00\u4e0b\u83b7\u53d6Cookie\u7684VBA\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"visualbasic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Private Declare Function InternetGetCookieEx Lib \"wininet.dll\" Alias \"InternetGetCookieExA\" ( _\n    ByVal URL As String, ByVal cookieName As String, ByVal cookieData As String, _\n    ByRef Size As Integer, ByVal Flags As Integer, ByVal pReserved As Long) As Boolean\n\nPrivate Function getCookie(ByVal URL As String) As String\n  Dim Buffer As String * 8096\n  If InternetGetCookieEx(URL, vbNullString, Buffer, 8096, INTERNET_COOKIE_HTTPONLY, 0) Then\n    getCookie = Buffer\n  Else\n    getCookie = \"\"\n  End If\nEnd Function<\/pre>\n\n\n\n<p>\u4ee5\u4e0a\u5c31\u662f\u83b7\u53d6Cookie\u7684VBA\u4ee3\u7801\uff0c\u662f\u4e0d\u662f\u5f88\u7b80\u6d01\uff1f\u63a5\u4e0b\u6765\uff0c\u6211\u4f1a\u4e00\u6b65\u6b65\u5730\u89e3\u91ca\u8fd9\u6bb5\u4ee3\u7801\u7684\u542b\u4e49\u548c\u7528\u6cd5\u3002<\/p>\n\n\n\n<p><strong>Step 1\uff1a\u5bfc\u5165wininet.dll\u5e93<\/strong><\/p>\n\n\n\n<p>\u5728\u4ee3\u7801\u7684\u7b2c\u4e00\u884c\uff0c\u6211\u4eec\u4f7f\u7528\u4e86<code>Declare<\/code>\u8bed\u53e5\u6765\u5bfc\u5165\u4e86<code>wininet.dll<\/code>\u5e93\u3002\u8fd9\u4e2a\u5e93\u5305\u542b\u4e86\u7528\u4e8e\u5904\u7406Internet\u8fde\u63a5\u7684\u4e00\u4e9b\u51fd\u6570\u3002\u8fd9\u4e00\u6b65\u662f\u4e3a\u4e86\u540e\u9762\u80fd\u591f\u8c03\u7528\u5176\u4e2d\u7684\u51fd\u6570\u6765\u83b7\u53d6Cookie\u4fe1\u606f\u3002<\/p>\n\n\n\n<p><strong>Step 2\uff1a\u7f16\u5199\u83b7\u53d6Cookie\u7684\u51fd\u6570<\/strong><\/p>\n\n\n\n<p>\u5728\u8fd9\u4e00\u6b65\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a<code>getCookie<\/code>\u7684\u51fd\u6570\uff0c\u5b83\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570<code>URL<\/code>\uff0c\u5373\u8981\u83b7\u53d6Cookie\u4fe1\u606f\u7684\u7f51\u7ad9\u5730\u5740\u3002\u51fd\u6570\u5185\u90e8\u9996\u5148\u58f0\u660e\u4e86\u4e00\u4e2a\u540d\u4e3a<code>Buffer<\/code>\u7684\u5b57\u7b26\u4e32\u53d8\u91cf\uff0c\u7528\u4e8e\u5b58\u50a8\u83b7\u53d6\u5230\u7684Cookie\u4fe1\u606f\u3002\u7136\u540e\uff0c\u6211\u4eec\u8c03\u7528\u4e86\u4e4b\u524d\u5bfc\u5165\u7684<code>InternetGetCookieEx<\/code>\u51fd\u6570\u6765\u83b7\u53d6Cookie\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u51fd\u6570\u7684\u53c2\u6570\u5206\u522b\u662f\u7f51\u7ad9\u7684URL\u3001Cookie\u540d\u79f0\uff08\u5728\u8fd9\u91cc\u6211\u4eec\u4f20\u5165\u4e86<code>vbNullString<\/code>\uff0c\u8868\u793a\u83b7\u53d6\u6240\u6709Cookie\uff09\u3001<code>Buffer<\/code>\u7528\u4e8e\u5b58\u50a8\u6570\u636e\u7684\u53d8\u91cf\u3001<code>Size<\/code>\u662f<code>Buffer<\/code>\u7684\u5927\u5c0f\u3001<code>Flags<\/code>\u7528\u4e8e\u6307\u5b9a\u83b7\u53d6\u7684Cookie\u7c7b\u578b\uff0c\u4ee5\u53ca<code>pReserved<\/code>\u53c2\u6570\u3002<\/p>\n\n\n\n<p><strong>Step 3\uff1a\u5224\u65ad\u83b7\u53d6\u662f\u5426\u6210\u529f<\/strong><\/p>\n\n\n\n<p>\u5728\u8fd9\u4e00\u6b65\uff0c\u6211\u4eec\u901a\u8fc7\u5224\u65ad<code>InternetGetCookieEx<\/code>\u51fd\u6570\u7684\u8fd4\u56de\u503c\u6765\u786e\u5b9a\u83b7\u53d6\u662f\u5426\u6210\u529f\u3002\u5982\u679c\u6210\u529f\uff0c\u6211\u4eec\u5c06<code>Buffer<\/code>\u4e2d\u7684\u6570\u636e\u8d4b\u503c\u7ed9<code>getCookie<\/code>\u51fd\u6570\u7684\u8fd4\u56de\u503c\uff0c\u5373\u6211\u4eec\u6210\u529f\u83b7\u53d6\u7684Cookie\u4fe1\u606f\u3002\u5982\u679c\u5931\u8d25\uff0c\u6211\u4eec\u5c06\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5c31\u662f\u6574\u4e2a\u83b7\u53d6Cookie\u7684\u8fc7\u7a0b\uff01\u662f\u4e0d\u662f\u5f88\u7b80\u5355\u5462\uff1f\u4f60\u53ea\u9700\u8981\u5c06\u8fd9\u6bb5\u4ee3\u7801\u5d4c\u5165\u5230\u4f60\u7684VBA\u9879\u76ee\u4e2d\uff0c\u7136\u540e\u8c03\u7528<code>getCookie<\/code>\u51fd\u6570\u5e76\u4f20\u5165\u4f60\u60f3\u8981\u83b7\u53d6\u7684\u7f51\u7ad9URL\uff0c\u5c31\u80fd\u8f7b\u677e\u5730\u83b7\u53d6\u5230Cookie\u4fe1\u606f\u5566\uff01<\/p>\n\n\n\n<p>\u5e0c\u671b\u4eca\u5929\u7684\u5206\u4eab\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5982\u679c\u4f60\u6709\u4efb\u4f55\u95ee\u9898\u6216\u60f3\u6cd5\uff0c\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u7559\u8a00\u4e0e\u6211\u4ea4\u6d41\u3002\u8bb0\u5f97\u5173\u6ce8\u6211\u7684\u535a\u5ba2\uff0c\u6211\u4f1a\u4e0d\u5b9a\u671f\u5206\u4eab\u66f4\u591a\u6709\u8da3\u7684\u6280\u5de7\u548c\u6559\u7a0b\u3002\u611f\u8c22\u5927\u5bb6\u7684\u9605\u8bfb\uff0c\u6211\u4eec\u4e0b\u6b21\u518d\u89c1\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6b22\u8fce\u6765\u5230\u6211\u7684\u535a\u5ba2\uff01\u4eca\u5929\u6211\u8981\u4e3a\u5927\u5bb6&#8230; <\/p>\n","protected":false},"author":1,"featured_media":3592,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[40],"tags":[65,36,49,66,67],"class_list":["post-3591","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vba","tag-cookie","tag-vba","tag-49","tag-66","tag-67"],"_links":{"self":[{"href":"https:\/\/www.bytetape.com\/index.php?rest_route=\/wp\/v2\/posts\/3591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bytetape.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bytetape.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bytetape.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bytetape.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3591"}],"version-history":[{"count":2,"href":"https:\/\/www.bytetape.com\/index.php?rest_route=\/wp\/v2\/posts\/3591\/revisions"}],"predecessor-version":[{"id":3600,"href":"https:\/\/www.bytetape.com\/index.php?rest_route=\/wp\/v2\/posts\/3591\/revisions\/3600"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bytetape.com\/index.php?rest_route=\/wp\/v2\/media\/3592"}],"wp:attachment":[{"href":"https:\/\/www.bytetape.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bytetape.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bytetape.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}