日期:2014-05-20 浏览次数:20792 次
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();