当前位置:编程学习 > C#/ASP.NET >>

httpwebrequest请求返回 图片乱码

        HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create("http://vip.qidian.com/BookReader/ChapterImage.aspx?bookId="+bookid+"&chapterId="+zjid+"&page=0");
        //HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create("http://a.65276588.cn/top.aspx");
        //HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create("http://my.qidian.com/User/Index.aspx");
        myReq.Timeout = 8000;
        myReq.ContentType = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
        //myReq.ContentType = "text/html";
        //myReq.Connection = "Keep-Alive";
        myReq.Headers.Add("Accept-Language", "zh-cn");
        myReq.Headers.Add("Accept-Encoding", "gzip, deflate");  
        
        myReq.Accept = "*/*";
        //myReq.Headers.Add("Host", "my.qidian.com");
        //myReq.Headers.Add("Connection", "Keep-Alive");
        myReq.CookieContainer = getcookie();
        myReq.Referer = "http://www.qidian.com";
        myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)";
        HttpWebResponse HttpWResp;
        try
        {
            HttpWResp = (HttpWebResponse)myReq.GetResponse();
        }
        catch (WebException ex)
        {
            return false;
        }

        Stream str = HttpWResp.GetResponseStream();

        System.Drawing.Image img = System.Drawing.Image.FromStream(str);// 这行报错 说传入的有错 --------------------编程问答-------------------- 快来人啊 --------------------编程问答-------------------- 快来人啊 --------------------编程问答-------------------- 把那个头  gzip, deflate 删除掉。否则,你就得自己去解压缩。 --------------------编程问答-------------------- gzip是一种数据格式   默认且目前仅使用deflate算法压缩data部分   
将body部分用gzip解压缩
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("");
            myHttpWebRequest.AllowAutoRedirect = true; 
            myHttpWebRequest.KeepAlive = true;
            myHttpWebRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*";
            myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 2.0.50727)";
            myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
            myHttpWebRequest.Method = "POST";

Visual Sniffer 捕捉提交信息

  --------------------编程问答-------------------- --------------------编程问答-------------------- 友情帮顶~~
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,