本文整理汇总了C#中System.Net.CookieCollection类的典型用法代码示例。如果您正苦于以下问题:C# CookieCollection类的具体用法?C# CookieCollection怎么用?C# CookieCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CookieCollection类属于System.Net命名空间,在下文中一共展示了CookieCollection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: Post
public static string Post(string url, IDictionary<string, string> parameters, CookieCollection cookies)
{
var postData = ParametersToWWWFormURLEncoded(parameters);
var postDataBytes = Encoding.ASCII.GetBytes(postData);
var request = (HttpWebRequest)WebRequest.Create(url);
if (cookies != null)
{
var container = new CookieContainer();
container.Add(cookies);
request.CookieContainer = container;
}
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postDataBytes.Length;
var outputStream = request.GetRequestStream();
outputStream.Write(postDataBytes, 0, postDataBytes.Length);
outputStream.Close();
var response = (HttpWebResponse)request.GetResponse();
var responseStreamReader = new StreamReader(response.GetResponseStream());
return responseStreamReader.ReadToEnd().Trim();
}
开发者ID:James137137,项目名称:chatter-bot-api,代码行数:26,代码来源:Utils.cs
示例17: 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
示例18: Serialize
public static void Serialize(CookieCollection cookies, Uri address, Stream stream)
{
var serializer = new DataContractSerializer(typeof (IEnumerable<Cookie>));
IEnumerable<Cookie> cookieList = cookies.OfType<Cookie>();
serializer.WriteObject(stream, cookieList);
}
开发者ID:Gluco,项目名称:AwfulMetro,代码行数:7,代码来源:CookieSerializer.cs
示例19: Get
/// <summary>
/// GET请求
/// </summary>
/// <param name="url">请求的URL</param>
/// <param name="encoding">字符集编码,默认UTF-8</param>
/// <param name="timeout">超时的时间,单是秒</param>
/// <param name="userAgent">代理字符串</param>
/// <param name="cookies">Cookie设置</param>
/// <returns>返回字符串</returns>
public static string Get(string url, Encoding encoding, int? timeout, string userAgent, CookieCollection cookies)
{
string res = string.Empty;
if (encoding == null)
{
encoding = DefaultEncoding;
}
try
{
HttpWebResponse response = CreateGetHttpResponse(url, timeout, userAgent, cookies);
using (var stream = response.GetResponseStream())
{
if (stream != null)
{
var reader = new StreamReader(stream, encoding);
var sb = new StringBuilder();
while (-1 != reader.Peek())
{
sb.Append(reader.ReadLine());
}
res = sb.ToString();
}
}
response.Close();
}
catch (Exception ex)
{
res = ex.Message;
}
return res;
}
开发者ID:SeayXu,项目名称:XY.OAuth-CSharp,代码行数:40,代码来源:Http.cs
示例20: CreatePostHttpResponse
/// <summary>
/// 创建POST方式的HTTP请求
/// </summary>
/// <param name="url">请求的URL</param>
/// <param name="parameters">随同请求POST的参数名称及参数值字典</param>
/// <param name="timeout">请求的超时时间</param>
/// <param name="userAgent">请求的客户端浏览器信息,可以为空</param>
/// <param name="requestEncoding">发送HTTP请求时所用的编码</param>
/// <param name="cookies">随同HTTP请求发送的Cookie信息,如果不需要身份验证可以为空</param>
/// <returns></returns>
public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary<string, string> parameters, int? timeout, string userAgent, Encoding requestEncoding, CookieCollection cookies)
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentNullException("url");
}
if (requestEncoding == null)
{
throw new ArgumentNullException("requestEncoding");
}
HttpWebRequest request = null;
request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
if (!string.IsNullOrEmpty(userAgent))
{
request.UserAgent = userAgent;
}
else
{
request.UserAgent = DefaultUserAgent;
}
if (timeout.HasValue)
{
request.Timeout = timeout.Value;
}
if (cookies != null)
{
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(cookies);
}
//如果需要POST数据
if (!(parameters == null || parameters.Count == 0))
{
StringBuilder buffer = new StringBuilder();
int i = 0;
foreach (string key in parameters.Keys)
{
if (i > 0)
{
buffer.AppendFormat("&{0}={1}", key, parameters[key]);
}
else
{
buffer.AppendFormat("{0}={1}", key, parameters[key]);
}
i++;
}
byte[] data = requestEncoding.GetBytes(buffer.ToString());
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
}
return request.GetResponse() as HttpWebResponse;
}
开发者ID:onedot,项目名称:XinGePushSDK.NET,代码行数:70,代码来源:HttpWebResponseUtility.cs
注:本文中的System.Net.CookieCollection类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论