c# 设置内存中的cookies

   1: [DllImport("wininet.dll", SetLastError = true)]
   2: public static extern bool InternetSetCookieEx(
   3:     string url,
   4:     string cookieName,
   5:     StringBuilder cookieData,
   6:     Int32 dwFlags,
   7:     IntPtr lpReserved);

 

   1: public static void SetCookieForBrowserControl(CookieContainer cc, Uri uri)
   2: {
   3:     String hostName = uri.Scheme + Uri.SchemeDelimiter + uri.Host;
   4:     Uri hostUri = new Uri(hostName);
   5:     foreach (Cookie cookie in cc.GetCookies(hostUri))
   6:     {
   7:         InternetSetCookieEx(hostName, cookie.Name, new StringBuilder(cookie.Value), 0, IntPtr.Zero);
   8:     }
posted @ 2012-12-08 14:41  天涯海客  阅读(532)  评论(0编辑  收藏  举报