日期:2014-05-17 浏览次数:20836 次
public static string GetCookiesHasCode(string strLoginURL, string strRefererURL, string strHttpLogin, string encodingcode, string cookieHeader)
{
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(strHttpLogin);//一定要经过encoding才能发送
try
{
// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strLoginURL);
myRequest.Method = "POST";
myRequest.Proxy = null;
myRequest.Timeout = 500;
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
myRequest.Referer = strRefererURL;
myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 2.0.50727)";
myRequest.KeepAlive = true;
myRequest.AllowAutoRedirect = true;
myRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*";
myRequest.Headers.Add("cookie:" + cookieHeader);
CookieContainer myCookieContainer = new CookieContainer();
myRequest.CookieContainer = myCookieContainer;