【转】C# 获取网页验证码

C#获取网页的验证码,并且显示在 picbox控件上

  1. HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://127.0.0.1/pic/Default.aspx");
  2. request.Timeout = 20000;
  3. request.ServicePoint.ConnectionLimit = 100;
  4. request.ReadWriteTimeout = 30000;
  5. request.Method = "GET";
  6. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  7. if (response.StatusCode != HttpStatusCode.OK)
  8. return;
  9. Stream resStream = response.GetResponseStream();
  10. this.pictureBox1.Image = new Bitmap(resStream);

  

读取页面返回的字符串,并显示在Lable上

  1. HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://10.225.105.18/pic/Default2.aspx");
  2. request.Timeout = 20000;
  3. request.ServicePoint.ConnectionLimit = 100;
  4. request.ReadWriteTimeout = 30000;
  5. request.Method = "GET";
  6. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  7. if (response.StatusCode != HttpStatusCode.OK)
  8. return;
  9. StreamReader reader = new StreamReader(response.GetResponseStream());
  10. this.label1.Text = reader.ReadLine();

 

注:http://127.0.0.1/pic/default.aspx 为你要访问的生成图片注册码的页面

posted @ 2013-08-04 17:56  zp_Alex  阅读(425)  评论(0编辑  收藏  举报