string url = "XXX";
HttpClient http = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Content = new StringContent("");
request.Headers.Accept.ParseAdd("application/json, text/javascript, */*;q=0.01");
request.Headers.Referrer = new Uri("XX");
request.Headers.UserAgent.ParseAdd(
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36"
);
request.Headers.Add("X-Requested-With", "XMLHttpRequest");
var response = http.Send(request);
bool IsGzip = response.Content.Headers.ContentEncoding.Contains("gzip");
if (IsGzip)
{
Stream stm = response.Content.ReadAsStreamAsync().Result;
string strHTML = string.Empty;
GZipStream gzip = new GZipStream(stm, CompressionMode.Decompress);//解压缩
using (StreamReader reader = new StreamReader(gzip, Encoding.UTF8))
{
strHTML = reader.ReadToEnd();
}
}
else
{
var outputStr = response.Content.ReadAsStringAsync().Result;
}