本文整理汇总了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
}
示例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
}
示例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));
}
示例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;
}
}