当前位置: 首页>>代码示例>>C#>>正文


C# CookieContainer.SetCookies方法代码示例

本文整理汇总了C#中System.Net.CookieContainer.SetCookies方法的典型用法代码示例。如果您正苦于以下问题:C# CookieContainer.SetCookies方法的具体用法?C# CookieContainer.SetCookies怎么用?C# CookieContainer.SetCookies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.CookieContainer的用法示例。


在下文中一共展示了CookieContainer.SetCookies方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: process

 public int process(CookieContainer cc)
 {
     System.Uri uri = null;
     string url = null;
     int res;
     res = pacifica_auth(mycallback);
     if(res == 0)
     {
         string test = System.Text.Encoding.ASCII.GetString(cookiedata);
         string[] lines = test.Split(new Char[] {'\n', '\r'});
         foreach(string lineraw in lines)
         {
             string line = lineraw;
             int cmplen = "URL:".Length;
             if(line.Length >= cmplen && line.Substring(0, cmplen).ToLower().Equals("URL:".ToLower()))
             {
                 url = lineraw.Substring(cmplen, lineraw.Length - cmplen).Trim();
                 uri = new System.Uri(url);
                 continue;
             }
             cmplen = "Set-Cookie:".Length;
             if(line.Length >= cmplen && line.Substring(0, cmplen).ToLower().Equals("Set-Cookie:".ToLower()))
             {
                 line = lineraw.Substring(cmplen, lineraw.Length - cmplen).Trim();
                 cc.SetCookies(uri, line);
             }
         }
     }
     return res;
 }
开发者ID:EMSL-MSC,项目名称:pacifica-auth,代码行数:30,代码来源:test.cs

示例2: Login

        public async Task<bool> Login(CancellationToken cancellationToken = default(CancellationToken))
        {
            if (IsLoogedIn)
                return true;

            var getConfigJob = ConfigurationService.GetClientConfig();

            var credentialsStr = Configuration.Username + ":" + Configuration.Password;
            var credentials64Str = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentialsStr));

            var authUri = new Uri((await getConfigJob).ApiConfig.BaseUrl,
                                  _apiUri.Replace("{username}", Configuration.Username));

            var authRequest = await CreateRequest(authUri);

            authRequest.Method = HttpMethod.Post;
            authRequest.Headers.Authorization = new AuthenticationHeaderValue("Basic", credentials64Str);

            var response = await SendRequest(authRequest);

            var cookies = new CookieContainer();
            cookies.SetCookies(authUri, String.Join(", ",response.Headers.GetValues("Set-Cookie")));

            SessionId = cookies.GetCookies(new Uri("http://gpodder.net"))["sessionid"];

#if DEBUG
           // if (SessionId != null)
                //Console.WriteLine("Authenticated");
#endif

            return true;
        }
开发者ID:pamidur,项目名称:Gpodder.NET,代码行数:32,代码来源:AuthenticationService.cs

示例3: GetUriCookieContainer

       public static CookieContainer GetUriCookieContainer(Uri uri)
       {
            CookieContainer l_Cookies = null;
            // Determine the size of the cookie
            int l_Datasize = 8192 * 16;
            StringBuilder l_CookieData = new StringBuilder(l_Datasize);

            if (!InternetGetCookieEx(uri.ToString(), null, l_CookieData, ref l_Datasize, InternetCookieHttponly, IntPtr.Zero))
            {
                if (l_Datasize < 0)
                    return null;

                // Allocate stringbuilder large enough to hold the cookie
                l_CookieData = new StringBuilder(l_Datasize);

                if (!InternetGetCookieEx(uri.ToString(), null, l_CookieData, ref l_Datasize, InternetCookieHttponly, IntPtr.Zero))
                    return null;
            }

            if (l_CookieData.Length > 0)
            {
                l_Cookies = new CookieContainer();
                l_Cookies.SetCookies(uri, l_CookieData.ToString().Replace(';', ','));
            }
            return l_Cookies;
       }
开发者ID:Jaroski,项目名称:Grepolis2Bot,代码行数:26,代码来源:CookieHelpers.cs

示例4: Gethtml

        public static string Gethtml(string URL, string cookie)
        {
            HttpWebRequest httpWebRequest;
            WebResponse wrp;

            httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(URL);
            CookieContainer co = new CookieContainer();
            Uri uri = new Uri(URL);
            co.SetCookies(uri, cookie);

            httpWebRequest.CookieContainer = co;

            httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            httpWebRequest.Accept =
                "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";

            httpWebRequest.UserAgent =
                "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)";
            httpWebRequest.Method = "get";

            wrp = (HttpWebResponse)httpWebRequest.GetResponse();

            string html = new StreamReader(wrp.GetResponseStream(), Encoding.UTF8).ReadToEnd();
            cookie = wrp.Headers.Get("Set-Cookie");

            return cookie+"\r\n\r\n\r\n=========================\r\n\r\n\r\n"+html;
        }
开发者ID:k2775739,项目名称:GetIWant,代码行数:27,代码来源:http.cs

示例5: SendHttpPostRequest

        /// <summary>
        /// ͬ������HttpRequest
        /// </summary>
        /// <param name="cookie"></param>
        /// <param name="url"></param>
        /// <param name="postData"></param>
        /// <returns></returns>
        public static HttpWebResponse SendHttpPostRequest(Cookie cookie, string url, string postData)
        {
            //���https�µ�֤������
            HttpRequestCredentialHelper.SetDefaultCredentialValidationLogic();

            var request = HttpWebRequest.Create(url) as HttpWebRequest;

            //������������ΪPOST
            request.Method = "POST";

            //����Post������
            if (!string.IsNullOrEmpty(postData))
            {
                request.ContentLength = postData.Length;
                request.ContentType = "application/x-www-form-urlencoded";
                using (var writer = new StreamWriter(request.GetRequestStream()))
                {
                    writer.Write(postData);
                    writer.Close();
                }
            }

            //��Cookie�����������÷�����֪����ǰ�û������
            var container = new CookieContainer();
            request.CookieContainer = container;
            if (cookie != null)
            {
                container.SetCookies(new Uri(Constants.ROOT_URL), string.Format("{0}={1}", cookie.Name, cookie.Value));
                var logger = DependencyResolver.Resolve<ILoggerFactory>().Create(typeof(HttpWebRequestHelper));
                logger.InfoFormat("HttpWebRequest CookieName:{0}, Value:{1}", cookie.Name, cookie.Value);
            }

            return request.GetResponse() as HttpWebResponse;
        }
开发者ID:codesharp,项目名称:cooper,代码行数:41,代码来源:HttpWebRequestHelper.cs

示例6: GetHtml

        public static string GetHtml(string URL, string cookie, out string header, string server)
        {
            HttpWebRequest httpWebRequest;
            HttpWebResponse webResponse;
            Stream getStream;
            StreamReader streamReader;
            string getString = "";
            httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(URL);
            httpWebRequest.Accept = "*/*";
            httpWebRequest.Referer = "http://yueche.woiche.com/";
            CookieContainer co = new CookieContainer();
            co.SetCookies(new Uri(server), cookie);
            httpWebRequest.CookieContainer = co;
            httpWebRequest.UserAgent =
                "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)";
            httpWebRequest.Method = "GET";
            webResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            header = webResponse.Headers.ToString();
            getStream = webResponse.GetResponseStream();
            streamReader = new StreamReader(getStream, Encoding.UTF8);
            getString = streamReader.ReadToEnd();

            streamReader.Close();
            getStream.Close();
            return getString;
        }
开发者ID:xiaohuangji,项目名称:myCSharp,代码行数:26,代码来源:Http.cs

示例7: GetHtmlByBytes

        public static byte[] GetHtmlByBytes(string host, string URL, byte[] byteRequest,string cookie, out string header)
        {
            long contentLength;    // 获取请求返回的内容的长度
            HttpWebResponse webResponse;
            Stream getStream;

            HttpWebRequest request = WebRequest.Create(URL) as HttpWebRequest;
            CookieContainer co = new CookieContainer();
            co.SetCookies(new Uri(host), cookie);

            request.CookieContainer = co;

            InitialHeadInfo(request);

            request.ContentLength = byteRequest.Length;
            Stream stream;
            stream = request.GetRequestStream();
            stream.Write(byteRequest, 0, byteRequest.Length);
            stream.Close();

            webResponse = request.GetResponse() as HttpWebResponse;

            contentLength = webResponse.ContentLength;

            header = webResponse.Headers.ToString();
            getStream = webResponse.GetResponseStream();

            byte[] outBytes = new byte[5000];
            outBytes = ReadFully(getStream);
            getStream.Close();
            request = null;
            webResponse = null;
            return outBytes;
        }
开发者ID:qq5013,项目名称:mERP-HD,代码行数:34,代码来源:GetHtmlInfo.cs

示例8: GetUriCookieContainer

        // This function returns cookie data based on a uniform resource identifier
        public static CookieContainer GetUriCookieContainer(Uri uri)
        {
            // First, create a null cookie container
              CookieContainer cookies = null;

              // Determine the size of the cookie
              var datasize = 8192 * 16;
              var cookieData = new StringBuilder(datasize);

              // Call InternetGetCookieEx from wininet.dll
              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 the cookie contains data, add it to the cookie container
              if (cookieData.Length > 0)
              {
            cookies = new CookieContainer();
            cookies.SetCookies(uri, cookieData.ToString().Replace(';', ','));
              }

              // Return the cookie container
              return cookies;
        }
开发者ID:popocats,项目名称:idle_master,代码行数:36,代码来源:frmBrowser.cs

示例9: CookieContainer

 public override string this[string name]
 {
     get
     {
         return this.innerCollection[name];
     }
     set
     {
         if ((name != "Content-Length") && (name != "Accept-Charset"))
         {
             if (name == "Cookie")
             {
                 if (this.request != null)
                 {
                     CookieContainer container = new CookieContainer();
                     container.SetCookies(this.request.RequestUri, value);
                     this.request.CookieContainer = container;
                 }
                 else
                 {
                     this.innerCollection[name] = value;
                 }
             }
             else
             {
                 this.innerCollection[name] = value;
             }
         }
     }
 }
开发者ID:npenin,项目名称:uss,代码行数:30,代码来源:ClientWebHeaderCollection.cs

示例10: GetIECookies

 /// <summary>
 /// Gets the URI cookie container.
 /// </summary>
 /// <param name="uri">The URI.</param>
 /// <returns></returns>
 internal static CookieContainer GetIECookies(Uri uri)
 {
     CookieContainer cookies = null;
     try
     {
         // Determine the size of the cookie
         int datasize = 8192 * 16;
         StringBuilder cookieData = new StringBuilder(datasize);
         if (!InternetGetCookieEx(uri.ToString(), null, cookieData, ref datasize, (uint)InternetFlags.INTERNET_COOKIE_HTTPONLY, 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,
                 (uint)InternetFlags.INTERNET_COOKIE_HTTPONLY,
                 IntPtr.Zero))
                 return null;
         }
         if (cookieData.Length > 0)
         {
             cookies = new CookieContainer();
             cookies.SetCookies(uri, cookieData.ToString().Replace(';', ','));
         }
     }
     catch { }
     return cookies;
 }
开发者ID:CrackHD,项目名称:vk9,代码行数:36,代码来源:Win32CookieHack.cs

示例11: ImportCookiesFromIE

        public static CookieContainer ImportCookiesFromIE()
        {
            var cookie = new CookieContainer();
            string targetUrl;
            string plusCookie;

            targetUrl = "https://plus.google.com";
            plusCookie = GetProtectedModeIECookieValue(targetUrl).Replace(';', ',');
            cookie.SetCookies(new Uri(targetUrl), plusCookie);

            targetUrl = "https://accounts.google.com";
            plusCookie = GetProtectedModeIECookieValue(targetUrl).Replace(';', ',');
            cookie.SetCookies(new Uri(targetUrl), plusCookie);

            targetUrl = "https://talkgadget.google.com";
            plusCookie = GetProtectedModeIECookieValue(targetUrl).Replace(';', ',');
            cookie.SetCookies(new Uri(targetUrl), plusCookie);

            return cookie;
        }
开发者ID:namoshika,项目名称:SnkLib.Web.GooglePlus,代码行数:20,代码来源:PlatformClientFactoryEx.cs

示例12: GetCookieContainerForUrl

 public static CookieContainer GetCookieContainerForUrl(Uri url)
 {
     CookieContainer container = new CookieContainer();
     string cookieHeaders = RetrieveIECookiesForUrl(url.AbsoluteUri);
     if (cookieHeaders.Length > 0)
     {
         try { container.SetCookies(url, cookieHeaders); }
         catch (CookieException) { }
     }
     return container;
 }
开发者ID:neoKushan,项目名称:CleanModQueue,代码行数:11,代码来源:CookieManager.cs

示例13: GetUriCookieContainer

        public static CookieContainer GetUriCookieContainer(Uri uri)
        {
            CookieContainer cookies = null;
            string cookieString = GetCookieString(uri);

            if (cookieString.Length > 0)
            {
                cookies = new CookieContainer();
                cookies.SetCookies(uri, cookieString.Replace(';', ','));
            }
            return cookies;
        }
开发者ID:baiyunping333,项目名称:seo-marketing,代码行数:12,代码来源:Internet.cs

示例14: ExtractAuthCookiesFromUrl

 public static CookieCollection ExtractAuthCookiesFromUrl(string url)
 {
     Uri uriBase = new Uri(url);
     Uri uri = new Uri(uriBase, "/");
     // call WinInet.dll to get cookie.
     string stringCookie = CookieReader.GetCookie(uri.ToString());
     if (string.IsNullOrEmpty(stringCookie)) return null;
     stringCookie = stringCookie.Replace("; ", ",").Replace(";", ",");
     // use CookieContainer to parse the string cookie to CookieCollection
     CookieContainer cookieContainer = new CookieContainer();
     cookieContainer.SetCookies(uri, stringCookie);
     return cookieContainer.GetCookies(uri);
 }
开发者ID:dream-365,项目名称:toolkit,代码行数:13,代码来源:CookieReader.cs

示例15: GetUriCookieContainer

        /// <summary>
        /// Gets the URI cookie container.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <returns></returns>
        public static CookieContainer GetUriCookieContainer(Uri uri)
        {
            CookieContainer cookies = null;
            // Determine the size of the cookie

            string cookieData = GetUriCookies(uri);

            if (cookieData.Length > 0)
            {
                cookies = new CookieContainer();
                cookies.SetCookies(uri, cookieData.Replace(';', ','));
            }
            return cookies;
        }
开发者ID:pkmnfrk,项目名称:busy,代码行数:19,代码来源:NativeApi.cs


注:本文中的System.Net.CookieContainer.SetCookies方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。