首页 > 代码库 > HttpWebResponse对gzip格式返回结果的处理

HttpWebResponse对gzip格式返回结果的处理

  HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); HttpWebResponse webResponse = (System.Net.HttpWebResponse)webRequest.GetResponse();            Stream streamReceive = webResponse.GetResponseStream();  if (webResponse.ContentEncoding.ToLower().Contains("gzip"))                {                    //gzip格式                    streamReceive = new GZipStream(streamReceive, CompressionMode.Decompress);                } using (System.IO.StreamReader sr = new System.IO.StreamReader(streamReceive, encoding))                {                    responseData = sr.ReadToEnd();                }

 

HttpWebResponse对gzip格式返回结果的处理