.Net HttpWebRequest返回为乱码

原因为网站使用了gzi进行压缩,而HttpResponse默认不处理

httpRequest = (HttpWebRequest)WebRequest.Create(entity.AccountUrl);

httpResponse =(HttpWebResponse)httpRequest.GetResponse();

stream st = httpResponse.GetResponseStream();

reader = new StreamReader(new GZipStream(st, CompressionMode.Decompress), Encoding.GetEncoding("utf-8"));

bodys = reader.ReadToEnd();

 

你可能感兴趣的:(.net开发)