{"id":551,"date":"2017-07-17T22:23:24","date_gmt":"2017-07-17T14:23:24","guid":{"rendered":"https:\/\/blog.freesilo.com\/?p=551"},"modified":"2017-07-17T22:23:24","modified_gmt":"2017-07-17T14:23:24","slug":"c-%e8%ae%be%e7%bd%ae%e7%b3%bb%e7%bb%9fcookie%ef%bc%8c%e5%8f%af%e7%94%a8%e4%ba%8e%e7%a8%8b%e5%ba%8f%e7%99%bb%e9%99%86%e5%90%8e%e5%85%8d%e7%99%bb%e9%99%86%e8%b7%b3%e8%bd%ac%e5%88%b0web","status":"publish","type":"post","link":"https:\/\/freesilo.com\/?p=551","title":{"rendered":"C# \u8bbe\u7f6e\u7cfb\u7edfCookie\uff0c\u53ef\u7528\u4e8e\u7a0b\u5e8f\u767b\u9646\u540e\u514d\u767b\u9646\u8df3\u8f6c\u5230WEB"},"content":{"rendered":"<p>\u672c\u6bb5\u4ee3\u7801\u662f\u5728\u524d\u5e74\u7f16\u5199\u7684\u4e00\u4e2a\u96c6\u56e2OA\u5de5\u5177\u4e2d\u7528\u5230\u7684\uff0c\u5f53\u65f6\u7684\u60c5\u666f\u662f\u5229\u7528Winform\u7a0b\u5e8f\u5b9e\u73b0OA\u7684\u767b\u9646\u4ee5\u53ca\u6d88\u606f\u63a8\u9001\u534f\u8bae\u3002\u5904\u7406\u4ee3\u529e\u548c\u4ee3\u9605\u7684\u65f6\u5019\u7531\u4e8e\u5f53\u65f6\u534f\u8bae\u6bd4\u8f83\u590d\u6742\u6240\u4ee5\u6ca1\u6709\u8fdb\u884cWinForm\u7248\u7684\u5b9e\u73b0\uff0c\u53ea\u80fd\u8df3\u8f6c\u3002\u4f46\u662f\u8df3\u8f6c\u4e0d\u53ef\u80fd\u91cd\u65b0\u767b\u9646\uff0c\u6240\u4ee5\u624d\u4f1a\u6709\u4e00\u4e0b\u8fd9\u6bb5\u4ee3\u7801\u3002\u4e2a\u4eba\u89c9\u5f97\u8fd8\u662f\u6bd4\u8f83\u4e0d\u9519\u7684\uff0c\u4ee5\u540e\u5e94\u8be5\u4f1a\u7528\u5230\u3002<br \/>\n\u8bbe\u7f6e\u7cfb\u7edf\u7684Cookie\u4e3b\u8981\u7528\u5230\u7684\u662fwininet.dll\u6a21\u5757\uff1a<\/p>\n<blockquote><p><strong>wininet.dll<\/strong><br \/>\nwininet.dll\u662fWindows\u5e94\u7528\u7a0b\u5e8f\u7f51\u7edc\u76f8\u5173\u6a21\u5757\u3002<\/p><\/blockquote>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/\/ &lt;summary&gt;\r\n\/\/\/ \u5199\u5165\u51fd\u6570\r\n\/\/\/ &lt;\/summary&gt;\r\n\/\/\/ &lt;param name=&quot;lpszUrlName&quot;&gt;&lt;\/param&gt;\r\n\/\/\/ &lt;param name=&quot;lbszCookieName&quot;&gt;&lt;\/param&gt;\r\n\/\/\/ &lt;param name=&quot;lpszCookieData&quot;&gt;&lt;\/param&gt;\r\n\/\/\/ &lt;returns&gt;&lt;\/returns&gt;\r\n&#x5B;DllImport(&quot;wininet.dll&quot;, CharSet = CharSet.Auto, SetLastError = true)]\r\npublic static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);\r\n\r\n\/\/\/ &lt;summary&gt;\r\n\/\/\/ \u8bfb\u53d6\u51fd\u6570\r\n\/\/\/ &lt;\/summary&gt;\r\n\/\/\/ &lt;param name=&quot;lpszUrlName&quot;&gt;&lt;\/param&gt;\r\n\/\/\/ &lt;param name=&quot;lbszCookieName&quot;&gt;&lt;\/param&gt;\r\n\/\/\/ &lt;param name=&quot;lpszCookieData&quot;&gt;&lt;\/param&gt;\r\n\/\/\/ &lt;param name=&quot;lpdwSize&quot;&gt;&lt;\/param&gt;\r\n\/\/\/ &lt;returns&gt;&lt;\/returns&gt;\r\n&#x5B;DllImport(&quot;wininet.dll&quot;, CharSet = CharSet.Auto, SetLastError = true)]\r\npublic static extern bool InternetGetCookie(string lpszUrlName, string lbszCookieName, StringBuilder lpszCookieData, ref int lpdwSize);\r\n\r\n\/\/\/ &lt;summary&gt;\r\n\/\/\/ \u68c0\u6d4b\u9519\u8bef\u51fd\u6570\r\n\/\/\/ &lt;\/summary&gt;\r\n\/\/\/ &lt;returns&gt;&lt;\/returns&gt;\r\n&#x5B;DllImport(&quot;kernel32.dll&quot;)]\r\npublic static extern Int32 GetLastError();\r\n<\/pre>\n<p>\u4e0a\u9762\u7684\u5b9a\u4e49\u5df2\u7ecf\u51fa\u6765\u4e86\uff0c\u4e0b\u9762\u4e3b\u8981\u662f\u7528\u6cd5\uff1a<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nInternetSetCookie(&quot;http:\/\/office.**********.com\/&quot;, &quot;LKS_CurUser&quot;, &quot;asdasdasdasd;expires=Sun,22-Feb-2099 00:00:00 GMT&quot;);\/\/\u8bbe\u7f6e\u767b\u5f55\u7528\u6237\u7684Cookie\u5e76\u8bbe\u7f6e\u65f6\u95f4\uff0c\u8ba9\u5b83\u6210\u4e3a\u53ef\u4f20\u9012\u7684\u6c38\u4e45Cookie\r\n<\/pre>\n<p>\u6ce8\u610f\uff1a\u4f7f\u7528\u65f6\u8bf7\u6ce8\u610f\u63a7\u5236Cookie\u7684\u6709\u6548\u65f6\u957f\uff0c\u907f\u514d\u7559\u4e0b\u5b89\u5168\u9690\u60a3\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6bb5\u4ee3\u7801\u662f\u5728\u524d\u5e74\u7f16\u5199\u7684\u4e00\u4e2a\u96c6\u56e2OA\u5de5\u5177\u4e2d\u7528\u5230\u7684\uff0c\u5f53\u65f6\u7684\u60c5\u666f\u662f\u5229\u7528Winform\u7a0b&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/freesilo.com\/?p=551\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-551","post","type-post","status-publish","format-standard","hentry","category-csharp"],"_links":{"self":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=551"}],"version-history":[{"count":1,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/551\/revisions"}],"predecessor-version":[{"id":552,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/551\/revisions\/552"}],"wp:attachment":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}