日期:2014-05-17  浏览次数:20995 次

紧急求助:WebBrowser
是想要读取 某网页的验证码。

目前已经找到该验证码src="CheckCode.aspx",下一步该怎么办?


------解决方案--------------------
验证码一般保存在session里,你需要取session信息
------解决方案--------------------

            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);