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


C# CookieContainer.SetCookies方法代码示例

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


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

示例1: SetCookies_InvalidInput_Throws

 public static void SetCookies_InvalidInput_Throws()
 {
     CookieContainer cc = new CookieContainer();
     Assert.Throws<ArgumentNullException>(() => cc.SetCookies(null, "")); // Null uri
     Assert.Throws<ArgumentNullException>(() => cc.SetCookies(u5, null)); // Null header
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:6,代码来源:CookieContainerTest.cs

示例2: SetCookies_Invalid

        public static void SetCookies_Invalid()
        {
            CookieContainer cc = new CookieContainer();

            Assert.Throws<ArgumentNullException>(() => cc.SetCookies(null, "")); //Null uri
            Assert.Throws<ArgumentNullException>(() => cc.SetCookies(new Uri("http://contoso.com"), null)); //Null header
        }
开发者ID:natemcmaster,项目名称:corefx,代码行数:7,代码来源:CookieContainerTest.cs

示例3: SetCookies_InvalidData_Throws

 public static void SetCookies_InvalidData_Throws(Uri uri, string cookieHeader)
 {
     CookieContainer cc = new CookieContainer();
     Assert.Throws<CookieException>(() => cc.SetCookies(uri, cookieHeader));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:5,代码来源:CookieContainerTest.cs

示例4: get_response

 public string get_response(string url, string method, string post, string cookie)
 {
     string str_return = "";
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
     request.Method = method;
     if (!String.IsNullOrEmpty(post))
     {
         byte[] send = Encoding.ASCII.GetBytes(post);
         request.ContentLength = send.Length;
         request.ContentType = "application/x-www-form-urlencoded";
         request.KeepAlive = true;
         Stream stream = request.GetRequestStream();
         stream.Write(send, 0, send.Length);
         stream.Close();
     }
     if (!String.IsNullOrEmpty(cookie))
     {
         CookieContainer container = new CookieContainer();
         container.SetCookies(new Uri(url), cookie);
         request.CookieContainer = container;
     }
     this.txt_request.Text = get_request_header(request);
     try
     {
         HttpWebResponse response = (HttpWebResponse)request.GetResponse();
         StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
         str_return = reader.ReadToEnd();
         return str_return;
     }
     catch (WebException error)
     {
         return error.Message;
     }
 }
开发者ID:topomondher,项目名称:web_helper,代码行数:34,代码来源:frm_request_web_http_request.cs


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