下载远程验证码到本地

其实本质上就是把远程的图片Stream流下载到本地,用pictureBox展示出来而已

带上cookie,这样就可以肉眼识别

代码很简单,直接上了

前台也就是一个pictureBox控件

AutoLoginHelper autoLoginHelper=new AutoLoginHelper(Encoding.UTF8);
            CookieContainer cc=new CookieContainer();
            Stream stream=autoLoginHelper.GetImages("http://passport.csdn.net/ShowExPwd.aspx%22,string.Empty,Encoding.UTF8,ref cc);
            Image img = new Bitmap(stream);
            this.pictureBox1.Image = img;

public Stream GetImages(string url, string postData, Encoding encoding, ref CookieContainer cookieContainer)
        {
            byte[] postByte = encoding.GetBytes(postData);
            HttpWebRequest wr = System.Net.HttpWebRequest.Create(url) as HttpWebRequest;
            wr.CookieContainer = cookieContainer;
            wr.Method = "POST";
            wr.ContentType = "application/x-www-form-urlencoded";
            wr.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; MS-RTC LM 8; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
            wr.Referer = url;
            wr.CookieContainer = cookieContainer;
            wr.ContentLength = postByte.Length;
            Stream sr = wr.GetRequestStream();
            sr.Write(postByte, 0, postByte.Length);
            sr.Close();
            HttpWebResponse response = wr.GetResponse() as HttpWebResponse;
            System.IO.Stream responseStream = response.GetResponseStream();
            return responseStream;
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值