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


C# CookieContainer.Add方法代码示例

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


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

示例1: SendLoginData

        private async Task<bool> SendLoginData(string username, string password)
        {
            CookieContainer cookies = await _webManager.PostData(
                Constants.LOGIN_URL, string.Format(
                    "action=login&username={0}&password={1}",
                    username.Replace(" ", "+"),
                    WebUtility.UrlEncode(password)));

            if (cookies.Count < 2)
            {
                return false;
            }

            var fixedCookieContainer = new CookieContainer();

            // TODO: HUGE HACK. For some reason Windows Phone does not use the Domain Key on a cookie, but only the domain when making requests.
            // Windows 8 won't break on it, but Windows Phone will, since the Domain Key and Domain are different on SA.
            // We need to move this code to a more common place.

            foreach (Cookie cookie in cookies.GetCookies(new Uri(Constants.COOKIE_DOMAIN_URL)))
            {
                var fixedCookie = new Cookie(cookie.Name, cookie.Value, "/", ".somethingawful.com");
                fixedCookieContainer.Add(new Uri(Constants.COOKIE_DOMAIN_URL), fixedCookie);
            }

            await _localStorageManager.SaveCookie(Constants.COOKIE_FILE, cookies, new Uri(Constants.COOKIE_DOMAIN_URL));
            return true;
        }
开发者ID:Gluco,项目名称:AwfulMetro,代码行数:28,代码来源:AuthenticationManager.cs

示例2: PrimeDice

 public PrimeDice()
 {
     _CC = new CookieContainer();
     _CC.Add(new Cookie("user", "43579", "/", "primedice.com"));
     _CC.Add(new Cookie("password", "ea1a3c", "/", "primedice.com"));
     _CC.Add(new Cookie("betting", "1", "/", "primedice.com"));
 }
开发者ID:KBrizzle,项目名称:PrimeDiceBot,代码行数:7,代码来源:PrimeDice.cs

示例3: ConvertToCookieContainer

        /// <summary>
        /// convert cookies string to CookieContainer
        /// </summary>
        /// <param name="cookies"></param>
        /// <returns></returns>
        public static CookieContainer ConvertToCookieContainer(Dictionary<string, string> cookies)
        {
            CookieContainer cookieContainer = new CookieContainer();

            foreach (var cookie in cookies)
            {
                string[] strEachCookParts = cookie.Value.Split(';');
                int intEachCookPartsCount = strEachCookParts.Length;

                foreach (string strCNameAndCValue in strEachCookParts)
                {
                    if (!string.IsNullOrEmpty(strCNameAndCValue))
                    {
                        Cookie cookTemp = new Cookie();
                        int firstEqual = strCNameAndCValue.IndexOf("=");
                        string firstName = strCNameAndCValue.Substring(0, firstEqual);
                        string allValue = strCNameAndCValue.Substring(firstEqual + 1, strCNameAndCValue.Length - (firstEqual + 1));
                        cookTemp.Name = firstName;
                        cookTemp.Value = allValue;
                        cookTemp.Path = "/";
                        cookTemp.Domain = cookie.Key;
                        cookieContainer.Add(cookTemp);
                    }
                }
            }
            return cookieContainer;
        }
开发者ID:yonglehou,项目名称:ToolRepository,代码行数:32,代码来源:Http3Helper.cs

示例4: GetVideoUrl

        public override string GetVideoUrl(VideoInfo video)
        {
            CookieContainer newCc = new CookieContainer();
            foreach (Cookie c in cc.GetCookies(new Uri(@"https://www.filmon.com/")))
            {
                newCc.Add(c);
            }

            NameValueCollection headers = new NameValueCollection();
            headers.Add("Accept", "*/*");
            headers.Add("User-Agent", userAgent);
            headers.Add("X-Requested-With", "XMLHttpRequest");
            string webdata = GetWebData(video.VideoUrl, (string)video.Other, newCc, headers: headers);

            JToken jt = JObject.Parse(webdata) as JToken;
            JArray streams = jt.Value<JArray>("streams");
            video.PlaybackOptions = new Dictionary<string, string>();
            foreach (JToken stream in streams)
            {
                string serverUrl = stream.Value<string>("url");

                RtmpUrl res = new RtmpUrl(serverUrl);
                res.Live = true;
                res.PlayPath = stream.Value<string>("name");

                int p = serverUrl.IndexOf("live/?id");
                res.App = serverUrl.Substring(p);
                video.PlaybackOptions.Add(stream.Value<string>("quality"), res.ToString());
            }

            return video.PlaybackOptions.First().Value;
        }
开发者ID:leesanghyun2,项目名称:mp-onlinevideos2,代码行数:32,代码来源:FilmonUtil.cs

示例5: GetCookies_AddCookiesWithImplicitDomain_CookiesReturnedOnlyForExactDomainMatch

        public void GetCookies_AddCookiesWithImplicitDomain_CookiesReturnedOnlyForExactDomainMatch()
        {
            const string SchemePrefix = "http://";
            const string OriginalDomain = "contoso.com";

            var container = new CookieContainer();
            var cookie1 = new Cookie(CookieName1, CookieValue1);
            var cookie2 = new Cookie(CookieName2, CookieValue2) { Version = 1 };
            var uri = new Uri(SchemePrefix + OriginalDomain);
            container.Add(uri, cookie1);
            container.Add(uri, cookie2);

            var cookies = container.GetCookies(uri);
            Assert.Equal(2, cookies.Count);
            Assert.Equal(OriginalDomain, cookies[CookieName1].Domain);
            Assert.Equal(OriginalDomain, cookies[CookieName2].Domain);

            uri = new Uri(SchemePrefix + "www." + OriginalDomain);
            cookies = container.GetCookies(uri);
            Assert.Equal(0, cookies.Count);

            uri = new Uri(SchemePrefix + "x.www." + OriginalDomain);
            cookies = container.GetCookies(uri);
            Assert.Equal(0, cookies.Count);

            uri = new Uri(SchemePrefix + "y.x.www." + OriginalDomain);
            cookies = container.GetCookies(uri);
            Assert.Equal(0, cookies.Count);

            uri = new Uri(SchemePrefix + "z.y.x.www." + OriginalDomain);
            cookies = container.GetCookies(uri);
            Assert.Equal(0, cookies.Count);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:33,代码来源:CookieContainerTest.cs

示例6: button2_Click

        private void button2_Click(object sender, EventArgs e)
        {
            if (cookieForm.ShowDialog() == DialogResult.OK)
            {
                var site = new Uri(SteamSite._mainsite);
                var hugeCock = new CookieContainer();
                hugeCock.Add(site, new Cookie(CookieFrm.sesid, cookieForm.textBox1.Text));
                hugeCock.Add(site, new Cookie(CookieFrm.webtrade, cookieForm.textBox2.Text));

                var stlogin = cookieForm.textBox3.Text;
                if (stlogin.Length > 17)
                {
                    hugeCock.Add(site, new Cookie(CookieFrm.stlog, stlogin));
                    hugeCock.Add(site, new Cookie(CookieFrm.machauth + stlogin.Substring(0, 17), cookieForm.textBox4.Text));
                    hugeCock.Add(site, new Cookie(CookieFrm.sec, cookieForm.textBox5.Text));

                    Main.steam_srch.cookieCont = hugeCock;
                    Main.scanItems.UpdateCock(hugeCock);
                    Main.SaveBinary(Main.cockPath, Main.steam_srch.cookieCont);
                }
                else
                {
                    MessageBox.Show(CookieFrm.stlog + " parameter is not correct!", "Import Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

        }
开发者ID:lucaslittermentz,项目名称:SCMBot,代码行数:27,代码来源:SettingsFrm.cs

示例7: GenerateCookies

 public static CookieContainer GenerateCookies()
 {
   var cookies = new CookieContainer();
   var target = new Uri("http://steamcommunity.com");
   cookies.Add(new Cookie("sessionid", Settings.Default.sessionid) { Domain = target.Host });
   cookies.Add(new Cookie("steamLogin", Settings.Default.steamLogin) { Domain = target.Host });
   cookies.Add(new Cookie("steamparental", Settings.Default.steamparental) { Domain = target.Host });
   return cookies;
 }
开发者ID:Hamalikoff,项目名称:idle_master-master,代码行数:9,代码来源:CookieClient.cs

示例8: CreateAuthClient

        /// <summary>
        /// Create a client to make requests requiring authentication
        /// </summary>
        /// <returns></returns>
        protected RestClient CreateAuthClient()
        {
            RestClient client = CreateClient();

            CookieContainer container = new CookieContainer();
            container.Add(new Uri(AppSettings.ApiUri), new Cookie("ss-id", AppSettings.SsId));
            container.Add(new Uri(AppSettings.ApiUri), new Cookie("ss-pid", AppSettings.SsPid));
            client.CookieContainer = container;

            return client;
        }
开发者ID:Ontropix,项目名称:whowhat,代码行数:15,代码来源:RestService.cs

示例9: GenerateCookies

 private CookieContainer GenerateCookies()
 {
     var cookies = new CookieContainer();
     var target = new Uri("http://steamcommunity.com");
     cookies.Add(new Cookie("sessionid", Settings.Default.sessionid) { Domain = target.Host });
     cookies.Add(new Cookie("steamLogin", Settings.Default.steamLogin) { Domain = target.Host });
     cookies.Add(new Cookie("steamparental", Settings.Default.steamparental) { Domain = target.Host });
     cookies.Add(new Cookie("steamRememberLogin", Settings.Default.steamRememberLogin) { Domain = target.Host });
     cookies.Add(new Cookie(GetSteamMachineAuthCookieName(), Settings.Default.steamMachineAuth) { Domain = target.Host });
     return cookies;
 }
开发者ID:AlexanderSharykin,项目名称:CardIdleRemastered,代码行数:11,代码来源:CookieClient.cs

示例10: GetCapthcaFromPage

 private Bitmap GetCapthcaFromPage(string url)
 {
     HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
     CookieContainer cookieJar = new CookieContainer();
     cookieJar.Add(new Uri("http://forum.ipadiz.ru/"), new Cookie("phpbb3_jornv_k", ""));
     cookieJar.Add(new Uri("http://forum.ipadiz.ru/"), new Cookie("phpbb3_jornv_u", "1"));
     cookieJar.Add(new Uri("http://forum.ipadiz.ru/"), new Cookie("style_cookie", "null"));
     cookieJar.Add(new Uri("http://forum.ipadiz.ru/"), new Cookie("phpbb3_jornv_sid", _sid));
     request.CookieContainer = cookieJar;
     HttpWebResponse response = (HttpWebResponse) request.GetResponse();
     Stream st = response.GetResponseStream();
     Bitmap bitmap = new Bitmap(st);
     return bitmap;
 }
开发者ID:Tauders,项目名称:AutoReg,代码行数:14,代码来源:phpBBReg.cs

示例11: button2_Click

        private void button2_Click(object sender, EventArgs e)
        {
            if (cookieForm.ShowDialog() == DialogResult.OK)
            {
                var site = new Uri(SteamSite._mainsite);
                var hugeCock = new CookieContainer();
                hugeCock.Add(site, new Cookie(CookieFrm.sesid, cookieForm.textBox1.Text));
                hugeCock.Add(site, new Cookie(CookieFrm.webtrade, cookieForm.textBox2.Text));
                hugeCock.Add(site, new Cookie(CookieFrm.stlog, cookieForm.textBox3.Text));

                Main.steam_srch.cookieCont = hugeCock;
                Main.SaveBinary(Main.cockPath, Main.steam_srch.cookieCont);
            }
        }
开发者ID:EnekoBarret,项目名称:SCMBot,代码行数:14,代码来源:SettingsFrm.cs

示例12: 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

示例13: Get_Login

        public static CookieContainer Get_Login()
        {
            CookieContainer cc = new CookieContainer();
            string FormURL = "https://confluence.englishtown.com/dologin.action";
            //处理表单的绝对URL地址
            string FormData = "os_username=jason.cheng&[email protected]";
            //表单需要提交的参数,注意改为你已注册的信息。
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] data = encoding.GetBytes(FormData);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(FormURL);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
            //模拟一个UserAgent
            Stream newStream = request.GetRequestStream();
            newStream.Write(data, 0, data.Length);

            newStream.Close();

            request.CookieContainer = cc;

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            cc.Add(response.Cookies);
            Stream stream = response.GetResponseStream();
            string WebContent = new StreamReader(stream, System.Text.Encoding.Default).ReadToEnd();
            return cc;
        }
开发者ID:RuhuiCheng,项目名称:Hello-Word,代码行数:29,代码来源:WebTool.cs

示例14: OnIdentityProviderTapped

        private async void OnIdentityProviderTapped(object sender, TappedRoutedEventArgs e)
        {
            var identityProvider = (IdentityProvider)((FrameworkElement)e.OriginalSource).DataContext;

            var webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(
                        WebAuthenticationOptions.None,
                        new Uri(identityProvider.LoginUrl),
                        new Uri("http://authentication.brainthud.com/api/federationcallback/end"));

            var start = webAuthenticationResult.ResponseData.LastIndexOf('=') + 1;
            var nameIdentifier = webAuthenticationResult.ResponseData.Substring(start, webAuthenticationResult.ResponseData.Length - start);
            var cookies = this.getCookies(nameIdentifier);

            var uri = new Uri(@"http://www.brainthud.com/api/Cards/");
            var cookieContainer = new CookieContainer();

            foreach(var cookie in cookies)
            {
                var cookieItem = new Cookie(cookie.Key, cookie.Value);
                cookieContainer.Add(uri, cookieItem);
            }

            var handler = new HttpClientHandler();
            handler.CookieContainer =cookieContainer;
            var client = new HttpClient(handler);
            var response = client.GetAsync(uri).Result;
            var result = response.Content.ReadAsStringAsync().Result;
            var x = result;
        }
开发者ID:aenmeyk,项目名称:BrainThud,代码行数:29,代码来源:LoginView.xaml.cs

示例15: Replace

        public override ImageViewURLReplaceItem Replace(string url)
        {
            string replacedReferer = Pattern.Replace(url, string.IsNullOrEmpty(OptionReferer) ? Referer : OptionReferer);
            string contents;
            CookieContainer cookieContainer = new CookieContainer();
            using (HttpWebResponse res = InternetClient.GetResponse(replacedReferer, url, null))//refererで内容取得,画像urlをリファラとして送信
            {
                cookieContainer.Add(res.Cookies);
                if (res.StatusCode != HttpStatusCode.OK)
                {
                    throw new WebException("cannot get webdata for extract url");
                }
                using (Stream st = res.GetResponseStream())
                using (StreamReader sr = new StreamReader(st, Common.Options.InternetOptions.CurrentEncoding))
                {
                    contents = sr.ReadToEnd();
                }
            }

            string replacement = Pattern.Replace(url, Replacement);
            string extractReplacement = CorrectExtractRegex(replacement);
            string replacedExtractPattern = Pattern.Replace(url, ExtractPattern);
            string matchString = Regex.Match(contents, replacedExtractPattern).Value;
            string imageUrl = Regex.Replace(matchString, replacedExtractPattern, extractReplacement);

            ImageViewURLReplaceItem result = Uri.IsWellFormedUriString(imageUrl, UriKind.Absolute) ?
                new ImageViewURLReplaceItem(imageUrl, replacedReferer, cookieContainer) :
                ImageViewURLReplaceItem.Empty;

            return result;
        }
开发者ID:omega227,项目名称:DeanCC,代码行数:31,代码来源:ImageViewUrlExtractItem.cs


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