字符串WebService上先zip压缩再base64编码后传输

先对字符串进行zip压缩,再进行base64编码

public string ZipBase64(string xml)
        {
            //压缩
            string compressStr = "";
            byte[] compressBeforeByte = Encoding.GetEncoding("UTF-8").GetBytes(xml);
            try
            {
                MemoryStream ms = new MemoryStream();
                GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true);
                zip.Write(compressBeforeByte, 0, compressBeforeByte.Length);
                zip.Close();
                byte[] buffer = new byte[ms.Length];
                ms.Position = 0;
                ms.Read(buffer, 0, buffer.Length);
                ms.Close();
                compressStr= Convert.ToBase64String(buffer);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            //base64编码
            byte[] encData

你可能感兴趣的:(base64,压缩,编码)