public Bitmap GetCodeImage()
{
string cookieHeader = "rtime=1; ltime=1321858632937; cnzz_eid=98605368-1321679713-; cnzz_a644725=10; sin644725=none; ASP.NET_SessionId=zoojtrmg0jjb1cfkj5unpj3n; rtime=0; ltime=1321703051546; cnzz_eid=24475558-1321703043-http%3A//cn.bing.com/search%3Fq%3Dwww.100mai.net%26src%3DIE-SearchBox%26FORM";
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create("http://www.100mai.net/admin/checkCode.aspx");
CookieContainer co = new CookieContainer();
co.SetCookies(new Uri("http://www.100mai.net"), cookieHeader);
httpWebRequest.CookieContainer = co;
httpWebRequest.Accept = "*/*";
httpWebRequest.Referer = config.LoginUrl;
httpWebRequest.UserAgent = " Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727)";
httpWebRequest.Method = "GET";
httpWebRequest.Headers.Set("Accept-Encoding", "gzip, deflate");
httpWebRequest.Headers.Set("Accept-Language", "zh-CN");
httpWebRequest.KeepAlive = true;
HttpWebResponse webResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream responseStream = webResponse.GetResponseStream();
Image original = Image.FromStream(responseStream);
Bitmap bitMap = new Bitmap(original);
responseStream.Close();
return bitMap;
}
问题:为什么用同一个ASP.NET_SessionId每次获取的验证码不一样。
是按http://topic.csdn.net/u/20100604/18/fadb1e99-e010-4aad-9e4f-bf5f0f745ee1的方法改的。
------解决方案--------------------------------------------------------
http://www.haogongju.net/art/235438
------解决方案--------------------------------------------------------
验证码一次请求就重新生成的。你第一次get之后就别再刷了。
------解决方案--------------------------------------------------------
使用C#登录带验证码的网站
------解决方案--------------------------------------------------------