[C#] c# 获取 httponly cookie →→→→→进入此内容的聊天室

来自 , 2020-12-27, 写在 C#, 查看 203 次.
URL http://www.code666.cn/view/9c7aa2e1
  1. /// <summary>
  2. /// WinInet.dll wrapper
  3. /// </summary>
  4. internal static class CookieReader
  5. {
  6.     /// <summary>
  7.     /// Enables the retrieval of cookies that are marked as "HTTPOnly".
  8.     /// Do not use this flag if you expose a scriptable interface,
  9.     /// because this has security implications. It is imperative that
  10.     /// you use this flag only if you can guarantee that you will never
  11.     /// expose the cookie to third-party code by way of an
  12.     /// extensibility mechanism you provide.
  13.     /// Version:  Requires Internet Explorer 8.0 or later.
  14.     /// </summary>
  15.     private const int INTERNET_COOKIE_HTTPONLY = 0x00002000;
  16.  
  17.     [DllImport("wininet.dll", SetLastError = true)]
  18.     private static extern bool InternetGetCookieEx(
  19.         string url,
  20.         string cookieName,
  21.         StringBuilder cookieData,
  22.         ref int size,
  23.         int flags,
  24.         IntPtr pReserved);
  25.  
  26.     /// <summary>
  27.     /// Returns cookie contents as a string
  28.     /// </summary>
  29.     /// <param name="url"></param>
  30.     /// <returns></returns>
  31.     public static string GetCookie(string url)
  32.     {
  33.         int size = 512;
  34.         StringBuilder sb = new StringBuilder(size);
  35.         if (!InternetGetCookieEx(url, null, sb, ref size, INTERNET_COOKIE_HTTPONLY, IntPtr.Zero))
  36.         {
  37.             if (size < 0)
  38.             {
  39.                 return null;
  40.             }
  41.             sb = new StringBuilder(size);
  42.             if (!InternetGetCookieEx(url, null, sb, ref size, INTERNET_COOKIE_HTTPONLY, IntPtr.Zero))
  43.             {
  44.                 return null;
  45.             }
  46.         }
  47.         return sb.ToString();
  48.     }
  49. }
  50. //csharp/5402

回复 "c# 获取 httponly cookie"

这儿你可以回复上面这条便签

captcha