【发布时间】:2011-08-06 17:57:28
【问题描述】:
这是压缩要发送到php代码的字符串的函数
public string Zip(string value)
{
//Transform string into byte[]
byte[] byteArray = Encoding.UTF8.GetBytes(value);
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();
}
并且正在使用
发送请求 string data = req.Zip(xml);
string resp = req.post(url,"&Data="+data);
我尝试使用 gzuncompress , gzdecode 但都产生数据错误任何人都知道为什么?
【问题讨论】:
标签: c# php mysql apache compression