程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C# 異步獲取驗證碼

C# 異步獲取驗證碼

編輯:C#入門知識

實現代碼如下 :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using CodeClassLibrary;
using System.IO;
using System.Net;

namespace ValidatorCodeDemo
{
    public partial class frmValidatorCode : Form
    {
        public frmValidatorCode()
        {
            InitializeComponent();
            this.GetCode();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            this.GetCode();
        }

        /// <summary>
        /// 產生新的驗證碼
        /// </summary>
        private void GetCode()
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://checkcode.taobao.com/auction/checkcode?sessionID=eb3f99fbe975258ea87bc24c235ab24f&r=1237173457015");
                Stream responseStream = ((HttpWebResponse)request.GetResponse()).GetResponseStream();
                Image original = Image.FromStream(responseStream);
                Bitmap bitMap = new Bitmap(original);
                this.pBoxCode.Image = bitMap;           //注意:替換為你的PictureBox控件名字
                responseStream.Close();

            }
            catch (Exception exception)
            {
                MessageBox.Show("ERROR:" + exception.Message);
            }
        }

    }
}

    

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved