[C#] 纯文本查看 复制代码 int bufferSize = 1024;
int revSize = 0;
byte[] array = null;
byte[] bytes = new byte[bufferSize];
using (System.IO.MemoryStream Ms = new System.IO.MemoryStream())
{
while (true)
{
bool readResult = InternetReadFile(hHttpOpenRequest, bytes, bufferSize, out revSize);
if (readResult && revSize > 0)
{
Ms.Write(bytes, 0, revSize);
}
else
{
break;
}
}
if (headerList.ContainsValue("gzip, deflate"))
{
using (System.IO.MemoryStream tempMs = new System.IO.MemoryStream())
{//执行这条后 tempMs为空,确定Ms有数据
new System.IO.Compression.GZipStream(Ms, System.IO.Compression.CompressionMode.Decompress,true).CopyTo(tempMs);
array = tempMs.ToArray();
}
}
else
array = Ms.ToArray();
}
|