C# winform 獲取網頁的圖片驗證碼,並顯示
阿新 • • 發佈:2019-02-07
C#獲取網頁的驗證碼,並且顯示在 picbox控制元件上
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://127.0.0.1/pic/Default.aspx");
- 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);
讀取頁面返回的字串,並顯示在Lable上
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://10.225.105.18/pic/Default2.aspx");
- request.Timeout = 20000;
- request.ServicePoint.ConnectionLimit = 100;
- request.ReadWriteTimeout = 30000;
- request.Method = "GET";
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- if (response.StatusCode != HttpStatusCode.OK)
- return;
- StreamReader reader = new StreamReader(response.GetResponseStream());
- this.label1.Text = reader.ReadLine();