Beispiel #1
0
        /// <summary>
        /// 返回uri的cookie集合
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        public static CookieContainer GetUriCookieContainer(this ExtendedWebBrowser browser, 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);
        }
Beispiel #2
0
 /// <summary>
 /// 给uri设置cookie,cookie为"field=value"
 /// </summary>
 /// <param name="uri"></param>
 /// <param name="cookie"></param>
 /// <returns></returns>
 public static bool SetUriCookie(this ExtendedWebBrowser browser, string uri, string cookie)
 {
     if (string.IsNullOrEmpty(uri) || string.IsNullOrEmpty(cookie))
     {
         return(false);
     }
     if (!cookie.Contains("="))
     {
         return(false);
     }
     InternetSetCookieEx(uri, null, cookie, 0, 0);
     return(true);
 }
Beispiel #3
0
 public WebBrowserExtendedEvents(ExtendedWebBrowser browser)
 {
     _Browser = browser;
 }
Beispiel #4
0
 public static bool EndBrowserSession(this ExtendedWebBrowser browser)
 {
     // 42 = INTERNET_OPTION_END_BROWSER_SESSION
     return(SetOption(42, null));
 }
Beispiel #5
0
 public static bool SupressCookiePersist(this ExtendedWebBrowser browser)
 {
     // 3 = INTERNET_SUPPRESS_COOKIE_PERSIST
     // 81 = INTERNET_OPTION_SUPPRESS_BEHAVIOR
     return(SetOption(81, 3));
 }