1. 程式人生 > >C# winform 獲取網頁的圖片驗證碼,並顯示

C# winform 獲取網頁的圖片驗證碼,並顯示

 

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