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


C# Net.CookieCollection类代码示例

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


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

示例1: GetCheckCodeImageStream

        //用于获取验证码图像的方法
        public Stream GetCheckCodeImageStream(string imageAddress, CookieContainer ccEntered, out CookieCollection ccReturned)
        {
            HttpWebRequest request;
            HttpWebResponse response;

            request = (HttpWebRequest)HttpWebRequest.Create(imageAddress);

            request.Method = "GET";
            request.ProtocolVersion = HttpVersion.Version11;
            //request.Connection = "keep-alive";
            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.861.0 Safari/535.2";
            request.Accept = "*/*";
            request.Referer = "http://buy.taobao.com/auction/buy_now.jhtml";

            //request.Headers.Add("Connection", "keep-alive");

            request.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
            request.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
            request.Headers.Add("Accept-Charset", "GBK,utf-8;q=0.7,*;q=0.3");

            request.CookieContainer = ccEntered;

            request.AllowAutoRedirect = true;

            response = (HttpWebResponse)request.GetResponse();
            ccReturned = response.Cookies;
            Stream s = response.GetResponseStream();
            response.Close();
            return s;
        }
开发者ID:KublaikhanGeek,项目名称:Taobao-Auction,代码行数:31,代码来源:AuctionOperations.cs

示例2: GetDealClosingCostTypesFromDeepBlue

 public static List<DeepBlue.Models.Entity.DealClosingCostType> GetDealClosingCostTypesFromDeepBlue(CookieCollection cookies)
 {
     // Admin/DealClosingCostTypeList?pageIndex=1&pageSize=5000&sortName=Name&sortOrder=asc
     List<DeepBlue.Models.Entity.DealClosingCostType> dealClosingCostTypes = new List<DeepBlue.Models.Entity.DealClosingCostType>();
     // Send the request
     string url = HttpWebRequestUtil.GetUrl("Admin/DealClosingCostTypeList?pageIndex=1&pageSize=5000&sortName=Name&sortOrder=asc");
     HttpWebResponse response = HttpWebRequestUtil.SendRequest(url, null, false, cookies, false, HttpWebRequestUtil.JsonContentType);
     if (response.StatusCode == System.Net.HttpStatusCode.OK) {
         using (Stream receiveStream = response.GetResponseStream()) {
             // Pipes the stream to a higher level stream reader with the required encoding format.
             using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) {
                 string resp = readStream.ReadToEnd();
                 if (!string.IsNullOrEmpty(resp)) {
                     JavaScriptSerializer js = new JavaScriptSerializer();
                     FlexigridData flexiGrid = (FlexigridData)js.Deserialize(resp, typeof(FlexigridData));
                     foreach (Helpers.FlexigridRow row in flexiGrid.rows) {
                         DeepBlue.Models.Entity.DealClosingCostType dealClosingType = new DeepBlue.Models.Entity.DealClosingCostType();
                         dealClosingType.DealClosingCostTypeID = Convert.ToInt32(row.cell[0]);
                         dealClosingType.Name = Convert.ToString(row.cell[1]);
                         dealClosingCostTypes.Add(dealClosingType);
                     }
                 }
                 else {
                 }
                 response.Close();
                 readStream.Close();
             }
         }
     }
     return dealClosingCostTypes;
 }
开发者ID:jsingh,项目名称:DeepBlue,代码行数:31,代码来源:DealImport.cs

示例3: CasAuthenticate

        private void CasAuthenticate(Site site, ref CookieCollection cookies, ref HtmlDocument document)
        {
            // read the parameters we need to know
            var form = document.GetElementbyId("fm1");
            var hidden = document.DocumentNode.Descendants("input").Where(a => a.Attributes["type"].Value == "hidden");

            var parameters = new StringBuilder();

            foreach (var p in hidden)
            {
                parameters.Append(string.Format("{0}={1}&", p.Attributes["name"].Value, p.Attributes["value"].Value));
            }

            var action = form.Attributes["action"];
            var username = ConfigurationSettings.AppSettings["username"];
            var password = ConfigurationSettings.AppSettings["password"];

            parameters.Append(string.Format("{0}={1}&", "username", username));
            parameters.Append(string.Format("{0}={1}", "password", password));

            // location to redirect back to the application
            var redirectLocation = string.Empty;
            MakeWebCallWithParameters("https://cas.ucdavis.edu:8443" + action.Value, parameters.ToString(), ref cookies, out redirectLocation);

            // get the ticket
            var ticketUrl = string.Format("https://cas.ucdavis.edu:8443/cas/login?service={0}", redirectLocation);
            var location = string.Empty;
            ErrorTypes errorType;
            MakeWebCall(ticketUrl, false, ref cookies, ref document, out location, out errorType);

            // get the aspx auth id
            var nothing = string.Empty;
            MakeWebCall(location, false, ref cookies, ref document, out nothing, out errorType);
        }
开发者ID:anlai,项目名称:IisMonitor,代码行数:34,代码来源:SiteService.cs

示例4: CreateGetHttpResponse

        /// <summary>  
        /// 创建GET方式的HTTP请求  
        /// </summary>  
        /// <param name="url">请求的URL</param>  
        /// <param name="timeout">请求的超时时间</param>  
        /// <param name="userAgent">请求的客户端浏览器信息,可以为空</param>  
        /// <param name="cookies">随同HTTP请求发送的Cookie信息,如果不需要身份验证可以为空</param>  
        /// <returns></returns>  
        public static HttpWebResponse CreateGetHttpResponse(string url, int? timeout, string userAgent, CookieCollection cookies)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("url");
            }
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.Method = "GET";
            request.UserAgent = DefaultUserAgent;
            if (!string.IsNullOrEmpty(userAgent))
            {
                request.UserAgent = userAgent;
            }
            if (timeout.HasValue)
            {
                request.Timeout = timeout.Value;
            }
            if (cookies != null)
            {
                request.CookieContainer = new CookieContainer();
                request.CookieContainer.Add(cookies);
            }

            return request.GetResponse() as HttpWebResponse;
        }
开发者ID:PuGuanyu,项目名称:MDWorkStation,代码行数:33,代码来源:HttpWebResponseUtility.cs

示例5: CreateGetHttpResponse

 public static HttpWebResponse CreateGetHttpResponse(string url, int timeout, string userAgent, CookieCollection cookies)
 {
     HttpWebRequest request = null;
     if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
     {
         //对服务端证书进行有效性校验(非第三方权威机构颁发的证书,如自己生成的,不进行验证,这里返回true)
         ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
         request = WebRequest.Create(url) as HttpWebRequest;
         request.ProtocolVersion = HttpVersion.Version10;    //http版本,默认是1.1,这里设置为1.0
     }
     else
     {
         request = WebRequest.Create(url) as HttpWebRequest;
     }
     request.Method = "GET";
     //设置代理UserAgent和超时
     //request.UserAgent = userAgent;
     //request.Timeout = timeout;
     if (cookies != null)
     {
         request.CookieContainer = new CookieContainer();
         request.CookieContainer.Add(cookies);
     }
     return request.GetResponse() as HttpWebResponse;
 }
开发者ID:byronv5,项目名称:CKMobile,代码行数:25,代码来源:HttpHelper.cs

示例6: GetHttpPage

        public string GetHttpPage(string strUrl, string strEncode, string strType,
            string strCookie, string strData, string strReferer, string strAcceptType,
            string strExtendHead, CookieCollection cookies)
        {
            try
            {
                Stream stream = GetHttpPageSteam(strUrl, strEncode, strType, strCookie, strData, strReferer, strAcceptType, strExtendHead, cookies);
                while (m_bRedirect)
                {
                    stream = GetHttpPageSteam(m_strRedirectUrl, strEncode, "get", strCookie, "", "", strAcceptType, strExtendHead, null);
                }
                if (stream == null)
                {
                    return "";
                }

                StreamReader sr = new StreamReader(stream, strEncode == "gb2312" ? Encoding.GetEncoding("gb2312") : Encoding.UTF8);
                string retStr = sr.ReadToEnd();
                sr.Close();
                return retStr; // UnZip(retStr);
            }
            catch (System.Exception e)
            {
                return "";
            }
        }
开发者ID:yuechuanbingzhi163,项目名称:myhistoryprojects,代码行数:26,代码来源:WebPost.cs

示例7: Rest

        public Rest()
        {
            InitializeComponent();

            // manual
            var request = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(new Uri("http://localhost:51401/SilverlightApplication1TestPage.html"));
            //var request2 = (HttpWebRequest)WebRequestCreator.BrowserHttp.Create(new Uri("http://localhost:51401/SilverlightApplication1TestPage.html"));

            // automatic
            WebRequest.RegisterPrefix("http://localhost:51401/", WebRequestCreator.ClientHttp);
            //WebRequest.RegisterPrefix("http://localhost:51401/", WebRequestCreator.BrowserHttp);

            // security
            //request.UseDefaultCredentials = false;
            //request.Credentials = new NetworkCredential("stiano", "mysecretpw", "domain");

            // cookies
            var cookies =
                new CookieCollection
                {
                    new Cookie("firstName", "Pete"),
                    new Cookie("lastName", "Brown"),
                    new Cookie("lastAccess", DateTime.Now.ToString(CultureInfo.InvariantCulture))
                };

            request.CookieContainer = new CookieContainer();
            request.CookieContainer.Add(new Uri("http://localhost:51401/SilverlightApplication1TestPage.html"), cookies);

            request.BeginGetResponse(OnRequestCompleted, request);
        }
开发者ID:stiano,项目名称:sl4,代码行数:30,代码来源:Rest.xaml.cs

示例8: BuildUnitTestCookies

        /// <summary>
        /// Builds a unit test for a cookie collection.
        /// </summary>
        /// <param name="testType"> The test type.</param>
        /// <param name="cookies"> The cookie collection.</param>
        /// <returns> An edited cookie collection.</returns>
        public CookieCollection BuildUnitTestCookies(UnitTestType testType, CookieCollection cookies)
        {
            CookieCollection changedCookies = null;
            IHtmlFormUnitTest tester = null;

            // Call FillForm
            switch (testType)
            {
                case UnitTestType.BufferOverflow:
                    tester = new BufferOverflowTester((BufferOverflowTesterArgs)this.Arguments);
                    break;
                case UnitTestType.DataTypes:
                    tester = new DataTypesTester((DataTypesTesterArgs)this.Arguments);
                    break;
                case UnitTestType.SqlInjection:
                    tester = new SqlInjectionTester((SqlInjectionTesterArgs)this.Arguments);
                    break;
                case UnitTestType.XSS:
                    tester = new XssInjectionTester((XssInjectionTesterArgs)this.Arguments);
                    break;
            }

            if ( tester != null )
                changedCookies = tester.FillCookies(cookies);

            return changedCookies;
        }
开发者ID:molekilla,项目名称:Ecyware_GreenBlue_Inspector,代码行数:33,代码来源:UnitTester.cs

示例9: Response

 public Response(String statusDescription, int statusCode, String body, CookieCollection cookies)
 {
     _statusDescription = statusDescription;
     _statusCode = statusCode;
     _cookies = cookies;
     _body = body;
 }
开发者ID:EventFabric,项目名称:dotnet-api,代码行数:7,代码来源:Response.cs

示例10: GetCookies

 public static IEnumerable<Cookie> GetCookies(CookieCollection cookies)
 {
     foreach (Cookie cookie in cookies)
     {
         yield return cookie;
     }
 }
开发者ID:labeuze,项目名称:source,代码行数:7,代码来源:Cookies.cs

示例11: FindCapitalDistributionDetail

 public static CapitalDistributionDetail FindCapitalDistributionDetail(CookieCollection cookies, int fundID, decimal? capitalDistributionAmount, DateTime? capitalDistributionDate, DateTime? capitalDistributionDueDate)
 {
     CapitalDistributionDetail detail = null;
     // Send the request
     string query = string.Empty;
     string resp = string.Empty;
     query = "&fundId=" + fundID + "&capitalDistributionAmount=" + capitalDistributionAmount + "&capitalDistributionDate=" + capitalDistributionDate + "&capitalDistributionDueDate=" + capitalDistributionDueDate;
     string url = HttpWebRequestUtil.GetUrl("CapitalCall/FindCapitalDistributionDetail?" + query);
     HttpWebResponse response = HttpWebRequestUtil.SendRequest(url, null, false, cookies, false, HttpWebRequestUtil.JsonContentType);
     if (response.StatusCode == System.Net.HttpStatusCode.OK) {
         using (Stream receiveStream = response.GetResponseStream()) {
             // Pipes the stream to a higher level stream reader with the required encoding format.
             using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) {
                 resp = readStream.ReadToEnd();
                 if (!string.IsNullOrEmpty(resp)) {
                     JavaScriptSerializer js = new JavaScriptSerializer();
                     detail = (CapitalDistributionDetail)js.Deserialize(resp, typeof(CapitalDistributionDetail));
                 }
                 else {
                 }
                 response.Close();
                 readStream.Close();
             }
         }
     }
     return detail;
 }
开发者ID:jsingh,项目名称:DeepBlue,代码行数:27,代码来源:CapitalDistribution.cs

示例12: AddNewCookieContainer

        public static void AddNewCookieContainer(int userId, CookieCollection cookieCollection)
        {
            if (instance.globalCookieCollection.ContainsKey(userId))
            {
                //System.Threading.Monitor.Enter(this);
                //try
                //{
                    instance.globalCookieCollection[userId].Add(cookieCollection);
                //}
                //finally
                //{
                //    System.Threading.Monitor.Exit(this);
                //}

            }
            else
                //System.Threading.Monitor.Enter(this);
                //try
                //{
                    instance.globalCookieCollection.Add(userId, cookieCollection);
                //}
                //finally
                //{
                //    System.Threading.Monitor.Exit(this);
                //}

            return;
        }
开发者ID:clarencemorse,项目名称:myzilla,代码行数:28,代码来源:CookieManager.cs

示例13: AddCommonHeadersToHttpRequest

        public static void AddCommonHeadersToHttpRequest(
            HttpWebRequest request, CookieCollection cookies, RequestHeaders headers, Uri baseUri,
            string referer, string method, bool followRedirect = true)
        {
            // add cookies to request
            var cookieContainer = new CookieContainer();
            if (cookies != null) cookieContainer.Add(cookies);
            request.CookieContainer = cookieContainer;

            request.Method = method;
            request.AllowAutoRedirect = followRedirect;
            request.KeepAlive = true;
            request.ContentType = headers.ContentType;
            request.PreAuthenticate = headers.PreAuthenticate;
            request.Host = headers.Host;
            request.UserAgent = headers.UserAgent;
            request.Accept = headers.Accept;
            request.Headers.Add("Accept-Language", headers.AcceptLanguage);
            request.Headers.Add("Accept-Encoding", headers.AcceptEncoding);
            request.Headers.Add("Accept-Charset", headers.AcceptCharset);

            Uri uriResult;
            if (Uri.TryCreate(baseUri, referer, out uriResult))
                request.Referer = uriResult.AbsoluteUri;
        }
开发者ID:Naviam,项目名称:Home-Accounting-Old,代码行数:25,代码来源:BankUtility.cs

示例14: GetHTML

        /// <summary>
        /// 获取网页HTML代码
        /// </summary>
        /// <param name="url">网址</param>
        /// <param name="cookie">cookie</param>
        /// <returns></returns>
        public static string GetHTML(string url, CookieCollection cookie)
        {
            CookieContainer cc = new CookieContainer();
            cc.Add(cookie);

            Uri uri = new Uri(url);
            HttpWebRequest hwReq = (HttpWebRequest)WebRequest.Create(uri);
            hwReq.CookieContainer = cc;

            HttpWebResponse hwRes;

            try
            {
                hwRes = (HttpWebResponse)hwReq.GetResponse();
            }
            catch
            {
                return "NONE";
            }

            hwReq.Method = "Get";
            hwReq.KeepAlive = false;

            StreamReader reader = new StreamReader(hwRes.GetResponseStream(), System.Text.Encoding.GetEncoding("GB2312"));
            return reader.ReadToEnd();
        }
开发者ID:mzry1992,项目名称:workspace,代码行数:32,代码来源:GetSource.cs

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


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