webrequest 如何读取java Servlet 生成的验证码
winform模式下,相通过webrequest读取网页验证码显在picturebox上面,但是网页的验证码是java servlet生成的,通常获取图片验证码的代码已经无效,部分代码如下:
try{
string LoginUrl = "http://buy.ccb.com/ImgCodeServlet?v=0.24919169838540256";
HttpWebRequest res = (HttpWebRequest)WebRequest.Create(LoginUrl);
res.Accept = "image/png,image/*;q=0.8,*/*;q=0.5";
res.CookieContainer = mycookiecontainer;
res.Method = "GET";
res.Referer = "http://buy.ccb.com/shoppingcart/ConfirmOrders.jhtml";
res.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0";
HttpWebResponse resp = (HttpWebResponse)res.GetResponse();
Stream resStream = resp.GetResponseStream();//得到验证码数据流
Bitmap sourcebm = new Bitmap(resStream);//初始化Bitmap图片
pc.Image = sourcebm;
resStream.Close();
}
catch(Exception ex)
{
throw;
}
网页的验证码抓包后的得到的获取地址是 http://buy.ccb.com/ImgCodeServlet?v=0.24919169838540256,请问各位大侠如何改下代码可以正确获取图片验证码显示在picturebox上。
------解决方案--------------------http://buy.ccb.com/ImgCodeServlet?v=0.24919169838540256
刚在浏览器里访问,这个地址已经无法打开,看了你的代码基本上正确。
所以问题在上面的地址错误。
------解决方案--------------------做验证码,就是要专门有几个人三天两头改程序,这样才安全嘛。