发布网友 发布时间:2024-10-21 22:00
共3个回答
热心网友 时间:2024-10-30 09:44
用抓包软件抓
GET http://hi.baidu.com/sys/file/getvcode?echoback=getVcodeDone&callback=bd__cbs__pp26jx HTTP/1.1
Accept: */*
Referer: http://hi.baidu.com/msg/index?from=redirect&ct=21&cm=1&tn=bmSendMessage&un=
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Accept-Encoding: gzip, deflate
Host: hi.baidu.com
Connection: Keep-Alive
Cookie: *
GET http://hiup.baidu.com/cgi-bin/genimg?3033313031303536303432333832303573706163653132393738373537363830343031303130307611FCA2A307190FEA0905FAFEF7C185 HTTP/1.1
Accept: */*
Referer: http://hi.baidu.com/msg/index?from=redirect&ct=21&cm=1&tn=bmSendMessage&un=
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Accept-Encoding: gzip, deflate
Host: hiup.baidu.com
Connection: Keep-Alive
Cookie: *
这两个数据包第一个是获取验证码Vcode,第二个是获取验证码图像
public class bdMsgVerifyCode
{
public string vcToken { get; set; } //genimg字符
public Image vcImg { get; set; } //验证码图片
public static bdMsgVerifyCode Create(string cookie)
{
bdMsgVerifyCode vc = new bdMsgVerifyCode();
WebClient client = new WebClient();
client.Headers.Add(HttpRequestHeader.Cookie, cookie);
client.Headers.Add(HttpRequestHeader.Referer, "http://hi.baidu.com/msg/index?from=redirect&ct=21&cm=1&tn=bmSendMessage&un=");
string html = client.DownloadString("http://hi.baidu.com/sys/file/getvcode?echoback=getVcodeDone&callback=bd__cbs__tppotb");
int start = html.IndexOf("\"")+1;
int end = html.IndexOf("\"", start);
vc.vcToken = html.Substring(start, end - start);
byte[] imgbuf = client.DownloadData("http://hiup.baidu.com/cgi-bin/genimg?" + vc.vcToken);
MemoryStream ms = new MemoryStream(imgbuf);
vc.vcImg = Image.FromStream(ms);
ms.Close();
return vc;
}
}
用法:
bdMsgVerifyCode vc = bdMsgVerifyCode.Create("***********");
pictureBox1.Image = vc.vcImg;
MessageBox.Show(vc.vcToken);
//vcToken与验证码一一对应,提交数据包时用
把cookie部分删了,这个发消息界面要登录帐号才能访问.,如果cookie有误就自动转到error界面..换成你登录帐号的cookie即刻 建议封装个user类然后传入user对象
热心网友 时间:2024-10-30 09:44
验证码的目的就是防止你用程序进行非法操作的热心网友 时间:2024-10-30 09:45
没办法获取 当你点击的时候就随机产生一个验证码