【C#基礎】byte二進制數組轉string


     //解析post請求數組返回的數組
     //解碼返回的二進制數組
        public string DecodeBytes(byte[] c)
        {
            string html = string.Empty;
            try
            {
                byte[] d = c;
                //Array.Copy(c, 44, d, 0, c.Length - 44);
                byte[] f = null;
                using (MemoryStream stream = new MemoryStream())
                {
                    using (GZipStream gZipStream = new GZipStream(new MemoryStream(d), CompressionMode.Decompress))
                    {
                        byte[] bytes = new byte[409600];
                        int n;
                        while ((n = gZipStream.Read(bytes, 0, bytes.Length)) != 0)
                        {
                            stream.Write(bytes, 0, n);
                        }
                        gZipStream.Close();
                    }
                    f = stream.ToArray();
                }
                html = System.Text.Encoding.UTF8.GetString(f);
            }
            catch (Exception ex)
            {
                html = ex.Message + "原始數據:" + System.Text.Encoding.Default.GetString(c);

                LogHelper.Log.Error("解碼返回的二進制數組異常", ex);
            }
            return html;
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM