asp.net网页解压GZip问题:GZip头中的幻数不正确,求正解. 还是求助中.百度了google了找不到答案.求大神帮助中. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我也碰到这个问题了其实很简单你先判断rsp.ContentEncoding的值是不是为空。。是的话就用stream 否则用Gzipstream using (FileStream sourceStream = new FileStream(sourceFile, FileMode.Open)) { byte[] quartetBuffer = new byte[4];//创建byte数组 int position = (int)sourceStream.Length - 4;//获取字节流长度 sourceStream.Position = position;//设置流当前位置 sourceStream.Read(quartetBuffer, 0, 4);//读取字节块并写入到缓冲区 sourceStream.Position = 0;//设置流当前位置 int checkLength = BitConverter.ToInt32(quartetBuffer, 0); byte[] buffer = new byte[checkLength + 100];//创建byte数组 //创建GZipStream对象,在执行完{}中的代码后自动释放该对象的资源 using (GZipStream decompressedStream = new GZipStream(sourceStream, CompressionMode.Decompress, true)) { int total = 0; for (int offset = 0; ; )//循环读取字节 { int bytesRead = decompressedStream.Read(buffer, offset, 100); //幻数在这里不正确 if (bytesRead == 0) break; offset += bytesRead; total += bytesRead; } //创建FileStream对象,在执行完{}中的代码后自动释放该对象的资源 using (FileStream destinationStream = new FileStream(destinationFile, FileMode.Create)) { destinationStream.Write(buffer, 0, total);//将缓冲区中的数据写入流 destinationStream.Flush();//清除缓冲区 } }不知如何修改,还请大神指教 如何点击一个按钮,然后在tabControl里生成一个选项卡,并在标签部分显示关闭的按钮。。 C#Winform程序经常自动关闭。 关于datagridview移动问题 c# 如何在 PC端 控制 手机设备的 键盘 如何获取当前窗口焦点所在的控件并进行操作 C#写的Com组件如何调用网页中的JS 请高手帮忙 自定义button控件,在鼠标在移过和按下的时候的透明部分会变成白色,怎么办 ? 谁告诉我面向对象的核心东西是什么 !!!请问高手.NET下分帧的问题!!! 求助:用C# Graphics画图,出现锯齿,怎么消除 wpf DataGridComboBoxColumn 的问题
{
byte[] quartetBuffer = new byte[4];//创建byte数组
int position = (int)sourceStream.Length - 4;//获取字节流长度
sourceStream.Position = position;//设置流当前位置
sourceStream.Read(quartetBuffer, 0, 4);//读取字节块并写入到缓冲区
sourceStream.Position = 0;//设置流当前位置
int checkLength = BitConverter.ToInt32(quartetBuffer, 0);
byte[] buffer = new byte[checkLength + 100];//创建byte数组
//创建GZipStream对象,在执行完{}中的代码后自动释放该对象的资源
using (GZipStream decompressedStream = new GZipStream(sourceStream, CompressionMode.Decompress, true))
{
int total = 0;
for (int offset = 0; ; )//循环读取字节
{
int bytesRead = decompressedStream.Read(buffer, offset, 100); //幻数在这里不正确
if (bytesRead == 0) break;
offset += bytesRead;
total += bytesRead;
}
//创建FileStream对象,在执行完{}中的代码后自动释放该对象的资源
using (FileStream destinationStream = new FileStream(destinationFile, FileMode.Create))
{
destinationStream.Write(buffer, 0, total);//将缓冲区中的数据写入流
destinationStream.Flush();//清除缓冲区
}
}
不知如何修改,还请大神指教