private const int INTERNET_COOKIE_HTTPONLY = 0x00002000;
private const int INTERNET_COOKIE = 0x2000;    
        [DllImport("wininet.dll", SetLastError = true)]
        private static extern bool InternetGetCookieEx(
        string url,
            string cookieName,
            StringBuilder cookieData,
        ref int size,
            int flags,
            IntPtr pReserved);
    
        /// <summary>
        /// Returns cookie contents as a string
        /// </summary>
        /// <param name="url">http://***.***.****</param>
        /// <returns></returns>
        public static string GetCookie(string url)
        {
                int size = 512;
                StringBuilder sb = new StringBuilder(size);
                if (!InternetGetCookieEx(url, null, sb, ref size, INTERNET_COOKIE, IntPtr.Zero))
                {
                    if (size < 0)
                    {
                        return null;
                    }
                    sb = new StringBuilder(size);
                    if (!InternetGetCookieEx(url, null, sb, ref size, INTERNET_COOKIE_HTTPONLY, IntPtr.Zero))
                    {
                        return null;
                    }
               }
            return sb.ToString();
        }

相关文章:

  • 2021-12-05
  • 2021-11-09
  • 2022-01-17
  • 2021-12-26
  • 2022-03-01
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-28
  • 2022-01-24
  • 2022-12-23
  • 2021-11-30
  • 2021-08-01
  • 2021-08-01
相关资源
相似解决方案