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);
}
}
}
}
补充:软件开发 , C# ,