首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

急找高手求解决,C#获取网页下的验证码显示到pictureBox下

2012-12-21 
急找高手求解决,C#获取网页上的验证码显示到pictureBox上本人想获取这个网站上的验证码显示在我的pictureB

急找高手求解决,C#获取网页上的验证码显示到pictureBox上
本人想获取这个网站上的验证码显示在我的pictureBox控件上, http://www.scjj.gov.cn:8635有能解决的请把代码发到我的邮箱jhjking@yeah.net里面,谢谢~~谢谢~
[最优解释]


        public static Stream GetStream(string url, CookieContainer cookieContainer)
        {
            HttpWebRequest httpWebRequest = null;
            HttpWebResponse httpWebResponse = null;

            try
            {
                httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
                httpWebRequest.CookieContainer = cookieContainer;
                httpWebRequest.ContentType = contentType;
                httpWebRequest.Referer = referer;
                httpWebRequest.Accept = accept;
                httpWebRequest.UserAgent = userAgent;
                httpWebRequest.Method = "GET";
                httpWebRequest.ServicePoint.ConnectionLimit = int.MaxValue;

                httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                Stream responseStream = httpWebResponse.GetResponseStream();

                return responseStream;
            }
            catch (Exception)
            {
                return null;
            }
        }

上楼敲错了。
[其他解释]
你看看img的连接,直接用webclient就可以下载
[其他解释]
我都试过了~还就是不行呢~
[其他解释]
引用:
你看看img的连接,直接用webclient就可以下载


要注意,一般来说,每次获取验证码会导致服务器端产生一个新的,这样验证码是可以获得,但是失去了意义。你可以从浏览器的缓存文件夹中抓取。
[其他解释]
1.得到image的路径(路径中可能有一些可变的参数,还有cookie必须带上)
2.下载,或直接以流的形式获取然后转换成图片
3.....
[其他解释]
引用:

本人想获取这个网站上的验证码显示在我的pictureBox控件上, http://www.scjj.gov.cn:8635有能解决的请把代码发到我的邮箱jhjking@yeah.net里面,谢谢~~谢谢~
我都试过了~还就是不行呢~  

[其他解释]
引用:
引用:本人想获取这个网站上的验证码显示在我的pictureBox控件上, http://www.scjj.gov.cn:8635有能解决的请把代码发到我的邮箱jhjking@yeah.net里面,谢谢~~谢谢~我都试过了~还就是不行呢~


那你调试下,可能是哪里出错了。
[其他解释]
引用:
1.得到image的路径(路径中可能有一些可变的参数,还有cookie必须带上)
2.下载,或直接以流的形式获取然后转换成图片
3.....
 http://www.scjj.gov.cn:8635可以进去看看么~
[其他解释]
http://www.scjj.gov.cn:8635/indexBitmap.aspx?flagPassword=0.6666577417182393
参数flagPassword后面是随机数,获取时要带上COOKIES

[其他解释]
引用:
http://www.scjj.gov.cn:8635/indexBitmap.aspx?flagPassword=0.6666577417182393
参数flagPassword后面是随机数,获取时要带上COOKIES
是呀~但是我获取出来就是一片空白的~
[其他解释]
引用:
那你调试下,可能是哪里出错了。
所以我都想求高手的代码了~
[其他解释]
引用:
引用:http://www.scjj.gov.cn:8635/indexBitmap.aspx?flagPassword=0.6666577417182393
参数flagPassword后面是随机数,获取时要带上COOKIES是呀~但是我获取出来就是一片空白的~


cookie的内容不全,你抓包看下
[其他解释]
直接用httpwebrequest访问:http://www.scjj.gov.cn:8635/indexBitmap.aspx?flagPassword=0.7081168430247833
这个地址的就可以了,flagPassword是一个0-1的随机数。
注意:
httpWebRequest.Referer = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5";
[其他解释]
一般网站的验证码都是用js回传的你找到这个网站的JS ,在JS 内有验证码的url,获取url把图片下载到本地,在传给PicterusBox
[其他解释]
引用:
本人想获取这个网站上的验证码显示在我的pictureBox控件上, http://www.scjj.gov.cn:8635有能解决的请把代码发到我的邮箱jhjking@yeah.net里面,谢谢~~谢谢~

 private void GetImg()
        {
            var httpWebRequest = (HttpWebRequest)HttpWebRequest.Create("http://www.scjj.gov.cn:8635/indexBitmap.aspx?flagPassword=0.5209738658265561");
            httpWebRequest.Credentials = CredentialCache.DefaultCredentials;
            httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            httpWebRequest.Accept = "image/png,image/*;q=0.8,*/*;q=0.5";
            httpWebRequest.Host = "www.scjj.gov.cn:8635";
            httpWebRequest.Referer = "http://www.scjj.gov.cn:8635/";
            httpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; CIBA; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)";


            httpWebRequest.Method = "Get";
            var webResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var getStream=webResponse.GetResponseStream())
            {
                int num;
                using (var ms = new MemoryStream())
                {
                    byte[] buffer = new byte[0x400];
                    do
                    {
                        num = getStream.Read(buffer, 0, buffer.Length);
                        if (num > 0)
                        {
                            ms.Write(buffer, 0, num);
                        }
                    } while (num > 0);
                    picCode.Image = System.Drawing.Image.FromStream(ms);
                }
            }
        }


[其他解释]
不传cookie是获取不到的

热点排行