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


C# CookieCollection.Add方法代码示例

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


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

示例1: GetReady

        public void GetReady () 
        {
		col = new CookieCollection ();	
		col.Add (new Cookie ("name1", "value1"));
		col.Add (new Cookie ("name2", "value2", "path2"));
		col.Add (new Cookie ("name3", "value3", "path3", "domain3"));		
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:CookieCollectionTest.cs

示例2: Add

	public void Add ()
	{
		try {
			Cookie c = null;
			col.Add (c);
			Assert.Fail ("#1");
		} catch (ArgumentNullException) {
		}
		
		// in the microsoft implementation this will fail,
		// so we'll have to fail to.
		try {
			col.Add (col);
			Assert.Fail ("#2");
		} catch (Exception) {
		}
		Assert.AreEqual (col.Count, 3, "#3");
		
		col.Add (new Cookie("name1", "value1"));		
		Assert.AreEqual (col.Count, 3, "#4");
		
		CookieCollection col2 = new CookieCollection();
		Cookie c4 = new Cookie("name4", "value4");
		Cookie c5 = new Cookie("name5", "value5");
		col2.Add (c4);
		col2.Add (c5);
		col.Add (col2);
		Assert.AreEqual (col.Count, 5, "#5");
		Assert.AreEqual (col ["NAME4"], c4, "#6");
		Assert.AreEqual (col [4], c5, "#7");
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:31,代码来源:CookieCollectionTest.cs

示例3: CreateCount11Container

        private CookieContainer CreateCount11Container()
        {
            CookieContainer cc1 = new CookieContainer();
            // Add(Cookie)
            cc1.Add(c1);
            cc1.Add(c2);
            cc1.Add(c3);
            cc1.Add(c4);

            // Add(CookieCollection)
            CookieCollection cc2 = new CookieCollection();
            cc2.Add(c5);
            cc2.Add(c6);
            cc2.Add(c7);
            cc1.Add(cc2);

            // Add(Uri, Cookie)
            cc1.Add(u4, c8);
            cc1.Add(u4, c9);

            // Add(Uri, CookieCollection)
            cc2 = new CookieCollection();
            cc2.Add(c10);
            cc2.Add(c11);
            cc1.Add(u5, cc2);

            return cc1;
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:28,代码来源:CookieContainerTest.cs

示例4: LogInAndEstablishSession

 private CookieCollection LogInAndEstablishSession(TDAmeritradeLoginCredentials creds)
 {
     var loginResponse = LoginCallResp(creds);
     var cc = new CookieCollection();
     cc.Add(loginResponse.Cookies);
     cc.Add(SecurityQuestionCallResp(loginResponse).Cookies);
     return cc;
 }
开发者ID:nicholasceliano,项目名称:FinanceMonitor,代码行数:8,代码来源:TDAmeritradeWebRequests.cs

示例5: GetCookieCollection

		/// <summary>
		/// urlに関連付けられたクッキーを取得します。
		/// </summary>
        public override CookieCollection GetCookieCollection(Uri url)
        {
            // 関係のあるファイルだけ調べることによってパフォーマンスを向上させる
            List<string> files = SelectFiles(url, GetAllFiles());
            List<Cookie> cookies = new List<Cookie>();

            foreach (string filepath in files)
            {
                cookies.AddRange(PickCookiesFromFile(filepath));
            }

            // Expiresが最新のもので上書きする
            cookies.Sort(CompareCookieExpiresAsc);
            CookieCollection collection = new CookieCollection();
            foreach (Cookie cookie in cookies)
            {
                try
                {
                    collection.Add(cookie);
                }
                catch (Exception ex)
                {
                    CookieGetter.Exceptions.Enqueue(ex);
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }

            return collection;
        }
开发者ID:JuroGandalf,项目名称:Ragnarok,代码行数:32,代码来源:IECookieGetter.cs

示例6: Regex

        Regex ifParse = new Regex(@"^([^<>=!]+)\s*([!<>=]+)\s*(.+)$", RegexOptions.Compiled); //variable names and operator match for if statement

        string getProcessorText()
        {
            if (string.IsNullOrEmpty(processorUrl) || itemUrl == null)
                return null;

            string url = string.Format("{0}?url={1}", processorUrl, HttpUtility.UrlEncode(itemUrl));
            CookieCollection ccollection = new CookieCollection();
            ccollection.Add(new Cookie("version", version.ToString()));
            ccollection.Add(new Cookie("platform", platform));
            if (processorUrl.StartsWith("http://www.navixtreme.com") && !string.IsNullOrEmpty(nxId))
                ccollection.Add(new Cookie("nxid", nxId));

            CookieContainer cc = new CookieContainer();
            cc.Add(new Uri(url), ccollection);
            return WebCache.Instance.GetWebData(url, cookies: cc);
        }
开发者ID:leesanghyun2,项目名称:mp-onlinevideos2,代码行数:18,代码来源:NaviXProcessor.cs

示例7: ProtectedGetCookies

        protected override CookieImportResult ProtectedGetCookies(Uri targetUrl)
        {
            if (IsAvailable == false)
                return new CookieImportResult(null,CookieImportState.Unavailable);
            try
            {
                var formatVersionRec = LookupEntry(SourceInfo.CookiePath, SELECT_QUERY_VERSION);
                int formatVersion;
                if (formatVersionRec.Count == 0
                    || formatVersionRec[0].Length == 0
                    || int.TryParse((string)formatVersionRec[0][0], out formatVersion) == false)
                    return new CookieImportResult(null,CookieImportState.ConvertError);

                string query;
                query = formatVersion < 7 ? SELECT_QUERY : SELECT_QUERY_V7;
                query = string.Format("{0} {1} ORDER BY creation_utc DESC", query, MakeWhere(targetUrl));
                var cookies = new CookieCollection();
                foreach (var item in LookupCookies(SourceInfo.CookiePath, query, rec => DataToCookie(rec, formatVersion)))
                    cookies.Add(item);
                return new CookieImportResult(cookies, CookieImportState.Success);
            }
            catch (CookieImportException ex)
            {
                TraceError(this, "取得に失敗しました。", ex.ToString());
                return new CookieImportResult(null, ex.Result);
            }
        }
开发者ID:rokugasenpai,项目名称:SnkLib.App.CookieGetter,代码行数:27,代码来源:BlinkCookieImporter.cs

示例8: NGetCookie

        public  /*CookieCollection*/ CookieContainer NGetCookie(string myUrl, string UserAgent)
        {

            CookieContainer MyCookie = new CookieContainer();
            CookieCollection Col = new CookieCollection();
            Uri url = new Uri(myUrl);
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            //if (_useProxy)
            //{
            //    httpWebRequest.Proxy = new WebProxy(_ipProxy, _portProxy);
            //    if (_ipProxy != "127.0.0.1" && _portProxy != 8118)
            //        httpWebRequest.Proxy.Credentials = new System.Net.NetworkCredential("UA_NALfVz2iFnd9", "AXz1M8FV2E");
            //}
            httpWebRequest.UserAgent = UserAgent; //"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36";
            httpWebRequest.CookieContainer = new CookieContainer();
            if (Col != null)
            {
                httpWebRequest.CookieContainer.Add(Col);
            }
            HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            httpWebResponse.Cookies = httpWebRequest.CookieContainer.GetCookies(httpWebRequest.RequestUri);
            if (httpWebResponse.Cookies != null)
            {
                Col.Add(httpWebResponse.Cookies);

            }

            MyCookie.Add(Col);

            //return Col;
            return MyCookie;
        }
开发者ID:molec1,项目名称:MySPM_NewParsers,代码行数:32,代码来源:Gde58Collector.cs

示例9: ProtectedGetCookies

 protected override CookieImportResult ProtectedGetCookies(Uri targetUrl)
 {
     if (IsAvailable == false)
         return new CookieImportResult(null, CookieImportState.Unavailable);
     try
     {
         var cookies = new CookieCollection();
         var res = CookieImportState.ConvertError;
         using (var sr = new System.IO.StreamReader(SourceInfo.CookiePath))
             while (!sr.EndOfStream)
             {
                 var line = sr.ReadLine();
                 if (line.StartsWith("cookies="))
                     cookies.Add(ParseCookieSettings(line));
                 res = CookieImportState.Success;
             }
         return new CookieImportResult(cookies, res);
     }
     catch (System.IO.IOException ex)
     {
         TraceError(this, "読み込みでエラーが発生しました。", ex.ToString());
         return new CookieImportResult(null,CookieImportState.AccessError);
     }
     catch (Exception ex)
     {
         TraceError(this, "読み込みでエラーが発生しました。", ex.ToString());
         return new CookieImportResult(null, CookieImportState.ConvertError);
     }
 }
开发者ID:rokugasenpai,项目名称:SnkLib.App.CookieGetter,代码行数:29,代码来源:WebkitQtCookieImporter.cs

示例10: SendHttpData

        public static string SendHttpData(
            string pageUrl,
            string postData,
            CookieContainer cookieContainer,
            CookieCollection cookieCollection)
        {
            //Console.WriteLine("SendData '{1}' to '{0}'", pageUrl, postData);

            HttpWebRequest httpWebRequest = (HttpWebRequest) WebRequest.Create(pageUrl);
            httpWebRequest.Method = "GET";
            httpWebRequest.UserAgent =
                "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080829 Firefox/2.0.0.17 (.NET CLR 3.5.30729)";
            httpWebRequest.CookieContainer = cookieContainer;
            httpWebRequest.KeepAlive = true;

            if (postData != null)
            {
                UTF8Encoding encoding = new UTF8Encoding();
                byte[] data = encoding.GetBytes(postData);

                httpWebRequest.Method = "POST";
                httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                httpWebRequest.ContentLength = data.Length;

                Stream postStream = httpWebRequest.GetRequestStream();
                postStream.Write(data, 0, data.Length);
                postStream.Close();
            }

            HttpWebResponse httpWebResponse = (HttpWebResponse) httpWebRequest.GetResponse();
            cookieCollection.Add(httpWebResponse.Cookies);
            cookieContainer.Add(cookieCollection);
            StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8);
            return streamReader.ReadToEnd();
        }
开发者ID:trippleflux,项目名称:jezatools,代码行数:35,代码来源:Http.cs

示例11: GetCartData

        public BaseApiResponse GetCartData(string username, string password)
        {
            var l = Login(username, password);

            var cc = new CookieCollection();

            cc.Add(new Cookie("CONSUMERCHOICE", "us/en_us", "/", "nike.com"));
            cc.Add(new Cookie("NIKE_COMMERCE_COUNTRY", "US", "/", "nike.com"));
            cc.Add(new Cookie("NIKE_COMMERCE_LANG_LOCALE", "en_US", "/", "nike.com"));
            cc.Add(new Cookie("nike_locale", "us/en_us", "/", "nike.com"));

            var hc = CookieHelper.GetAllCookiesFromHeader(l.Headers["Set-Cookie"], "nike.com");

            cc.Add(hc);

            return DoGet(CartUrl, null, cc);
        }
开发者ID:hasanqusay,项目名称:securecarts,代码行数:17,代码来源:NikeApi.cs

示例12: SetCookies

        public void SetCookies(IEnumerable<Cookie> cookies)
        {
            _currentCollection = new CookieCollection();
            foreach (var cookie in cookies) {
                _currentCollection.Add(cookie);
            }

            CookieContainer.Add(_currentCollection);
        }
开发者ID:djlewisxactware,项目名称:ModernHttpClient,代码行数:9,代码来源:NativeCookieHandler.cs

示例13: GetCookieTumenRealtyCityStar

        //подсунем кукии сайту citystar тюмень
        public CookieContainer GetCookieTumenRealtyCityStar(Uri myUrl)
        {
            //string[] cook = webBrowser.Document.Cookie.ToString().Split(new Char[] { '=', ';', ' ' });
            // получаю массив в виде: UID, 12341424151,,PID,1423523236,...
            CookieContainer MyCookie = new CookieContainer();
            CookieCollection Col = new CookieCollection();
            Uri url = myUrl;//new Uri(myUrl);
            Cookie CS_SESSION_ID = new Cookie("CS_SESSION_ID", "xnyh296mrt4i5to84z9boen5tk26nsz734hku8l19n3yhmm9qy");
            Cookie ASPNET_SessionId = new Cookie("ASP.NET_SessionId", "5btohi23q5j4f5h1z1nlof1z");

            Col.Add(CS_SESSION_ID);
            Col.Add(ASPNET_SessionId);

            //Cookie: CS_SESSION_ID=xnyh296mrt4i5to84z9boen5tk26nsz734hku8l19n3yhmm9qy; ASP.NET_SessionId=5btohi23q5j4f5h1z1nlof1z

            MyCookie.Add(url, Col);
            return MyCookie;
        }
开发者ID:molec1,项目名称:MySPM_NewParsers,代码行数:19,代码来源:DataDBNet.cs

示例14: OnScrape

        protected override string OnScrape(string url, HtmlNode elem)
        {
            var hash = SelectItem(elem, "[name=hash]").Attributes["value"].Value;
            var id = SelectItem(elem, "[name=id]").Attributes["value"].Value;
            var fname = SelectItem(elem, "[name=fname]").Attributes["value"].Value;
            var inhu = SelectItem(elem, "[name=inhu]").Attributes["value"].Value;
            var data = new NameValueCollection();
            data.Add("_vhash", SubstringBetween(elem.InnerHtml, "name: '_vhash', value: '", "'"));
            data.Add("fname", fname);
            data.Add("gfk", SubstringBetween(elem.InnerHtml, "name: 'gfk', value: '", "'"));
            data.Add("hash", hash);
            data.Add("id", id);
            data.Add("imhuman", "Proceed to video");
            data.Add("inhu", inhu);
            data.Add("op", "download1");
            data.Add("referer", "");
            data.Add("usr_login", "");

            var cookies = new CookieCollection();
            cookies.Add(new Cookie("file_id", SubstringBetween(elem.InnerHtml, "'file_id', '", "'")) { Domain = "www.thevideo.me" });
            cookies.Add(new Cookie("aff", SubstringBetween(elem.InnerHtml, "'aff', '", "'")) { Domain = "www.thevideo.me" });
            cookies.Add(new Cookie("lang", "1") { Domain = "www.thevideo.me" });
            //cookies.Add(new Cookie("ref_url", url) { Domain = "www.thevideo.me" });
            //cookies.Add(new Cookie("mlUserID", "dtwVzu8bAWsc") { Domain = "www.thevideo.me" });
            //cookies.Add(new Cookie("__cfduid", "d629171dd342b852f8ddabc37c85b978e1406816048462") { Domain = ".thevideo.me" });
            var nv = new NameValueCollection();
            nv.Add("Referer", url);
            var c = 0;
            var eval = String.Empty;
            var text = Properties.Resources.Unpacker;
            while (c++ < 6)
            {
                elem = Post(url, data, cookies, nv);
                eval = SubstringBetween(elem.InnerHtml, "eval", "</");
                if (!String.IsNullOrEmpty(eval))
                    break;
                Thread.Sleep(1000);
            }

            eval = "eval" + eval;
            eval = eval.Replace("\"", "\\x22");
            url = SubstringBetween(UnpackScript(text.Replace("X", eval)), "file:'", "'");
            return new Uri(url).AbsoluteUri;
        }
开发者ID:huoxudong125,项目名称:VideoSearch,代码行数:44,代码来源:TheVideo.cs

示例15: RepackCookie

            private CookieCollection RepackCookie(ReadOnlyCollection<OpenQA.Selenium.Cookie> cookies)
            {
                var pack = new CookieCollection();
                foreach (var c in cookies)
                {
                    pack.Add(new System.Net.Cookie(c.Name, c.Value, c.Path, c.Domain));
                }

                return pack;
            }
开发者ID:cupidshen,项目名称:misc,代码行数:10,代码来源:JsAgent.cs


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