国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

.net 獲取瀏覽器Cookie(包括HttpOnly)實例分享

2024-07-10 12:44:37
字體:
來源:轉載
供稿:網友

一、接口文件

代碼如下:
using System;
using System.ComponentModel;
using System.Net;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Text;

namespace CookieHandler
{
    internal sealed class INativeMethods
    {
        #region enums

        public enum ErrorFlags
        {
            ERROR_INSUFFICIENT_BUFFER = 122,
            ERROR_INVALID_PARAMETER = 87,
            ERROR_NO_MORE_ITEMS = 259
        }

        public enum InternetFlags
        {
            INTERNET_COOKIE_HTTPONLY = 8192, //Requires IE 8 or higher     
            INTERNET_COOKIE_THIRD_PARTY = 131072,
            INTERNET_FLAG_RESTRICTED_ZONE = 16
        }

        #endregion

        #region DLL Imports

        [SuppressUnmanagedCodeSecurity, SecurityCritical, DllImport("wininet.dll", EntryPoint = "InternetGetCookieExW", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
        internal static extern bool InternetGetCookieEx([In] string Url, [In] string cookieName, [Out] StringBuilder cookieData, [In, Out] ref uint pchCookieData, uint flags, IntPtr reserved);

        #endregion
    }
}

二、獲取cookie類

代碼如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Text;

namespace CookieHandler
{
    /// <SUMMARY></SUMMARY>
    /// 取得WebBrowser的完整Cookie。
    /// 因為默認的webBrowser1.Document.Cookie取不到HttpOnly的Cookie
    /// IE7不兼容,IE8可以,其它未知
    ///
    public class FullWebBrowserCookie
    {
        public static Dictionary<string, string> GetCookieList(Uri uri, bool throwIfNoCookie)
        {
            Dictionary<string, string> dict = new Dictionary<string, string>();

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江陵县| 西和县| 仪陇县| 桐庐县| 南华县| 余江县| 绥芬河市| 通化县| 邮箱| 揭西县| 泾源县| 大宁县| 鄂托克前旗| 绥德县| 武安市| 合作市| 林甸县| 印江| 庄浪县| 邓州市| 泰安市| 卫辉市| 紫金县| 五莲县| 桂林市| 延长县| 兴义市| 当涂县| 陕西省| 南召县| 临高县| 榆树市| 西乡县| 桂林市| 渭源县| 岚皋县| 梓潼县| 历史| 微博| 廉江市| 香格里拉县|