日期:2014-05-17 浏览次数:20995 次
HttpWebRequest request;
//验证码地址
string picpath = "http://localhost:8034/Controls/ValidateCode.aspx";
request = WebRequest.Create(picpath) as HttpWebRequest;
request.Method = "GET";
request.Timeout = 30000;
request.AllowAutoRedirect = true;
request.ContentType = "image/bmp";
request.UserAgent = "Mozilla/5.0 (Windows NT 5.2; rv:11.0) Gecko/20100101 Firefox/11.0";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"));
Bitmap sourcebm = new Bitmap(sr.BaseStream);
sr.Close();
//SetLuma(sourcebm);//灰度处理
//Repair(sourcebm);//修复
pictureBox1.Image = sourcebm;
//sourcebm.Save("veryfyCode.bmp");
try
{
/*
string _veryfyCode = Marshal.PtrToStringAnsi(OCR("veryfyCode.bmp", -1));
txt_Log.Text = _veryfyCode;
MessageBox.Show(_veryfyCode);