GZip头中指定的压缩模式在c#MVC中未知
我试图解压我的字符串,但我得到一个错误。 int rByte=sr.Read(byteArray,0,byteArray.Length)强> 获取此行中的错误。你能告诉我哪里做错了吗GZip头中指定的压缩模式在c#MVC中未知,c#,asp.net,asp.net-mvc,.net-4.5,C#,Asp.net,Asp.net Mvc,.net 4.5,我试图解压我的字符串,但我得到一个错误。 int rByte=sr.Read(byteArray,0,byteArray.Length) 获取此行中的错误。你能告诉我哪里做错了吗 public static string UnZip(string value, int Contentlength) { try { //Transform string into byte[] byte[] byteArray = new
public static string UnZip(string value, int Contentlength)
{
try
{
//Transform string into byte[]
byte[] byteArray = new byte[value.Length];
int indexBA = 0;
foreach (char item in value.ToCharArray())
{
byteArray[indexBA++] = (byte)item;
}
//Prepare for decompress
System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArray);
System.IO.Compression.GZipStream sr = new System.IO.Compression.GZipStream(ms,
System.IO.Compression.CompressionMode.Decompress);
//Reset variable to collect uncompressed result
byteArray = new byte[Contentlength];
//Decompress
int rByte = sr.Read(byteArray, 0, byteArray.Length);
//Transform byte[] unzip data to string
System.Text.StringBuilder sB = new System.Text.StringBuilder(rByte);
//Read the number of bytes GZipStream red and do not a for each bytes in
//resultByteArray;
for (int i = 0; i < rByte; i++)
{
sB.Append((char)byteArray[i]);
}
sr.Close();
ms.Close();
sr.Dispose();
ms.Dispose();
return sB.ToString();
}
catch (Exception ex)
{
return ex.Message;
}
}
public static string Zip(string value)
{
//Transform string into byte[]
byte[] byteArray = new byte[value.Length];
int indexBA = 0;
foreach (char item in value.ToCharArray())
{
byteArray[indexBA++] = (byte)item;
}
//Prepare for compress
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.IO.Compression.GZipStream sw = new System.IO.Compression.GZipStream(ms,
System.IO.Compression.CompressionMode.Compress);
//Compress
sw.Write(byteArray, 0, byteArray.Length);
//Close, DO NOT FLUSH cause bytes will go missing...
sw.Close();
//Transform byte[] zip data to string
byteArray = ms.ToArray();
System.Text.StringBuilder sB = new System.Text.StringBuilder(byteArray.Length);
foreach (byte item in byteArray)
{
sB.Append((char)item);
}
ms.Close();
sw.Dispose();
ms.Dispose();
return sB.ToString();
}
公共静态字符串解压(字符串值,int Contentlength)
{
尝试
{
//将字符串转换为字节[]
byte[]byteArray=新字节[value.Length];
int indexBA=0;
foreach(value.ToCharArray()中的字符项)
{
byteArray[indexBA++]=(字节)项;
}
//准备减压
System.IO.MemoryStream ms=新的System.IO.MemoryStream(byteArray);
System.IO.Compression.GZipStream sr=新的System.IO.Compression.GZipStream(ms,
系统。IO。压缩。压缩模式。解压缩);
//重置变量以收集未压缩的结果
byteArray=新字节[Contentlength];
//减压
int rByte=sr.Read(byteArray,0,byteArray.Length);
//将字节[]解压数据转换为字符串
System.Text.StringBuilder sB=新的System.Text.StringBuilder(rByte);
//读取GZipStream red中的字节数,并且不为中的每个字节指定一个
//结果字节数组;
对于(int i=0;i
我通过如下url发送值
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 0\0\0\0 0\0 0"xßDèTèbèTèbèTèVÌèNèhèDèDèDèDèJèaèbèxèTèTèOèT:VÌèNèhèEèEèEèw$½F4Å0\rHP'q±Eð5ZX¸pÇs×k5cn1ÀJDæDMybD:8Àq«»I%\aÒEÆ1ÙUOā8W\nóyè193; rúUúD+/(将字符串转换为字符数组,然后将其转换为字节数组充其量是可疑的。字符串
value
从何而来,以及它如何对二进制数据进行编码?我正在通过URL发送值我正在编辑我的代码请看一看