日期:2014-05-20  浏览次数:20792 次

应用程序验证码图片下载不对
http://fj.ac.10086.cn:8008/sso3/common/image.jsp?id=0.5101336622264985 这个地址下载的图

C# code

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url));
            request.Method = "GET";
            request.ContentType = "image/jpeg";
            request.CookieContainer = cc;
            request.KeepAlive = true;
            request.AllowAutoRedirect = true;
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; CIBA)";//"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 1.1.4322)";           
            request.Accept = "*/*";
            request.Headers.Add("Accept-Language: zh-cn");
            request.Headers.Add("Accept-Encoding: gzip,deflate");
            request.AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            //WebClient wc = new WebClient();
            //wc.DownloadFile(url, AppDomain.CurrentDomain.BaseDirectory + "1.jpg");

            Stream st = response.GetResponseStream();
            byte[] buffer = new byte[2048];
            st.Read(buffer, 0, buffer.Length);
            st.Close();
            FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + ImgIndex.ToString()+".jpg", FileMode.OpenOrCreate, FileAccess.Write);
            fs.Write(buffer,0,buffer.Length);
            fs.Flush();
            fs.Close();




图下载下来之后右边有少部分没显示 跟网页上的不同 求指导

------解决方案--------------------
你另存那个图片看下大小,然后看看你下载下来的图片大小

2个比较一下看看大小是否有差异,还是本身那个图片就不完整,逐个检查一下看看?

byte[] buffer = new byte[2048]; //将2048再调大点试试