标签:serial efi raw convert memory sel eth .text air
private static T GetDataCommonMethod<T>(string url, string host, HeaderData headerData) where T : class
{
//注意Host和请求基网址各个请求可能不同
var client = new WebClient();
var headerStr = $"Host: {host}" + "\n" +
"User-Agent: ......" + "\n" +
@"Accept: application/json, text/plain, */*" + "\n" +
"Accept-Encoding: gzip, deflate" + "\n" +
"Accept-Language: zh-cn" + "\n" +
$"Cookie: m={headerData.m}; u={headerData.u}; wx={headerData.wx}; ......" + "\n";
var rawHeaders = headerStr.Split(new[] { ‘\n‘, ‘\r‘ }, StringSplitOptions.RemoveEmptyEntries).ToList();
var headerPairs = rawHeaders.Select(x =>
{
var items = x.Split(new[] { ‘:‘ }, 2, StringSplitOptions.RemoveEmptyEntries);
var key = items[0].Trim();
var value = items[1].Trim();
return new ValueTuple<string, string>(key, value);
}).ToList();
headerPairs.ForEach(x =>
{
client.Headers.Set(x.Item1, x.Item2);
});
//先gzip解压再转string
byte[] rawBytes = client.DownloadData(url);
var stream = new MemoryStream(rawBytes);
GZipStream g = new GZipStream(stream, CompressionMode.Decompress);
//gzip最后四位是原始长度
var length = BitConverter.ToInt32(rawBytes, rawBytes.Length - 4);
byte[] bytes = new byte[length];
g.Read(bytes, 0, bytes.Length);
//编码是UTF8
string s0 = System.Text.Encoding.UTF8.GetString(bytes);
T result = JsonConvert.DeserializeObject<T>(s0);
return result;
}
标签:serial efi raw convert memory sel eth .text air
原文地址:http://www.cnblogs.com/Lulus/p/7872252.html