C#获取网页验证码

public void GetCodeImg()
        {

            string imgUrl = "http://icode.renren.com/getcode.do?t=register_1181254934&rk=600&rnd=1313288232918";

            this.pictureBox1.Image = Image.FromStream(WebRequest.Create(imgUrl).GetResponse().GetResponseStream());
            return;

            //或者:
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(imgUrl);
         
            request.Timeout = 20000;
            request.ServicePoint.ConnectionLimit = 100;
            request.ReadWriteTimeout = 30000;
            request.Method = "GET";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            if (response.StatusCode != HttpStatusCode.OK)
                return;
            Stream resStream = response.GetResponseStream();
            this.pictureBox1.Image = new Bitmap(resStream);
        }
在form上有一个pictureBox控件

注意开头:using System.Net;

刷新的按钮即响应即调用该函数。




你可能感兴趣的:(Stream,String,C#)