110,538
社区成员
发帖
与我相关
我的任务
分享
你是指的XHR的response结果?
internal String Get(string url )
{
if (!string.IsNullOrEmpty(Url))
{
WebClient web = new WebClient();
byte[] rs = web.DownloadData(url);
try
{
return Encoding.UTF8.GetString(UnZip(rs));
} catch (Exception ex)
{
// throw new Exception(ex.Message);
}
}
string.Empty;
}
/// <summary>
/// 解压
/// </summary>
/// <param name="packageBytes"></param>
/// <returns></returns>
internal Byte[] UnZip(byte[] packageBytes)
{
try
{
using (GZipStream gzip = new GZipStream(new MemoryStream(packageBytes), CompressionMode.Decompress))
{
using (MemoryStream msTemp = new MemoryStream())
{
int count = 0;
byte[] buffe = new byte[1024];
while ((count = gzip.Read(buffe, 0, buffe.Length)) > 0)
{
msTemp.Write(buffe, 0, count);
}
return msTemp.ToArray();
}
}
} catch
{
return packageBytes;
}
}