zoukankan      html  css  js  c++  java
  • 通过URL获取浏览器Cookie

    通过URL获取浏览器Cookie

    [DllImport("wininet.dll", SetLastError = true)]
    public static extern bool InternetGetCookieEx(
        string url,
        string cookieName,
        StringBuilder cookieData,
        ref int size,
        Int32 dwFlags,
        IntPtr lpReserved);
    
    private const Int32 InternetCookieHttponly = 0x2000;
    
    /// <summary>
    /// Gets the URI cookie container.
    /// </summary>
    /// <param name="uri">The URI.</param>
    /// <returns></returns>
    private static CookieContainer GetUriCookieContainer(Uri uri)
    {
        CookieContainer cookies = null;
        // Determine the size of the cookie
        int datasize = 8192 * 16;
        StringBuilder cookieData = new StringBuilder(datasize);
        if (!InternetGetCookieEx(uri.ToString(), null, cookieData, ref datasize, InternetCookieHttponly, IntPtr.Zero))
        {
            if (datasize < 0)
                return null;
            // Allocate stringbuilder large enough to hold the cookie
            cookieData = new StringBuilder(datasize);
            if (!InternetGetCookieEx(
                uri.ToString(),
                null, cookieData,
                ref datasize,
                InternetCookieHttponly,
                IntPtr.Zero))
                return null;
        }
        if (cookieData.Length > 0)
        {
            cookies = new CookieContainer();
            cookies.SetCookies(uri, cookieData.ToString().Replace(';', ','));
        }
        return cookies;
    }
    
  • 相关阅读:
    Promise对象
    前端跨域处理
    ajax
    增删改查
    2018牛客暑假多校三 E(KMP运用)
    2018牛客暑假多校三 C (平衡树)
    2018牛客暑假多校三 A(01背包)
    HDU 6315 (2018多校第二场)(线段树)
    2018暑假牛客多校二 C(凸包)
    HDU 6299(多校第一场B)(贪心)
  • 原文地址:https://www.cnblogs.com/wuyicqb/p/5516339.html
Copyright © 2011-2022 走看看