新开一个IE,复制图片地址是否能打开
有的生成图片的页面,判断了来源或者COOKIE,没有的话,是打不开的,需要伪造

解决方案 »

  1.   

    noyester 你说的cookies我有添加进去的,添加cookie代码Request.Headers["Cookie"]=imageCookie;这个imageCookie是我从第一次请求中取出来的!下载验证码图片的请求代码:
                      Request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);  
                    Request.Headers["Cookie"] = frmStatrWap.imageCookie;
                    WebProxy loProxy = new WebProxy("10.0.0.172", 80);
                    Request.UseDefaultCredentials = true;
                    Request.Proxy = loProxy;
                    Request.Method = "GET";
                    Request.Referer = frmStatrWap.url;
      

  2.   

    用Fiddle抓包后一个字节一个字节的对比,如果你的程序发的包和浏览器发的一样了,没理由打不开.另外,如果抓包的页面设计到二级域名,.NET自带的cookie会有各种奇怪的问题发生.
      

  3.   

    我没有给Request添加cookie,只是在Headers里面设置了cookieId;Request.Headers["Cookie"] = frmStatrWap.imageCookie;
      

  4.   

    如果单独用IE打开可以看到图片,那说明你的请求代码有问题,
    你要设置请求内容类型,即要设置 Content-Type,至于是什么值,你可以打开浏览器监控一下,看看请求图片时用的是什么Content-Type。
      

  5.   

    这是我获取QQ验证码的代码:        private static string contentType = "application/x-www-form-urlencoded";
            private static string accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";
            private static string userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Zune 4.7; BOIE9;ZHCN)";
            public static string referer = "http://ui.ptlogin2.qq.com/cgi-bin/login?appid=1006102&s_url=http://id.qq.com/index.html";
            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;
                }
            }直接这样使用就OK:img = Image.FromStream(Stream );你参考参考
      

  6.   

    我这边下载的验证码是手机wap网端的验证码。楼上的方法是下载不下来的!