如果服务器支持的话,你可以请服务器提供压缩数据:
var req = (HttpWebRequest)WebRequest.Create("http://your.server/url");
req.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
var webResponse = (HttpWebResponse)req.GetResponse();
var responseStream = webResponse.GetResponseStream();
if (webResponse.ContentEncoding.Contains("gzip", StringComparison.OrdinalIgnoreCase))
{
responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
}
else if (WebResponse.ContentEncoding.ToLower().Contains("deflate"))
{
responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);
}
var reader = new StreamReader(responseStream, Encoding.Default);
string html = reader.ReadToEnd();
webResponse.Close();
responseStream.Close();
详细情况: