示例#1
0
        public byte[] Encoding(string sourceStr)
        {
            var _encoding    = TextEncoding.GetEncoding(EncodePageName);
            var _sourceBytes = TextEncoding.UTF8.GetBytes(sourceStr);

            return(TextEncoding.Convert(TextEncoding.UTF8, _encoding, _sourceBytes));
        }
示例#2
0
 public byte[] Encoding(byte[] sourceBytes, TextEncoding sourceEncode)
 {
     return(TextEncoding.Convert(sourceEncode, TextEncoding.Default, sourceBytes));
 }
示例#3
0
 public byte[] Encoding(byte[] sourceBytes)
 {
     return(TextEncoding.Convert(TextEncoding.UTF8, TextEncoding.Default, sourceBytes));
 }
示例#4
0
 public byte[] Encoding(string sourceStr)
 {
     return(TextEncoding.Convert(TextEncoding.UTF8, TextEncoding.Default, TextEncoding.UTF8.GetBytes(sourceStr)));
 }
示例#5
0
 public byte[] Encoding(byte[] sourceBytes, TextEncoding sourceEncode)
 {
     byte[] convertBytes = TextEncoding.Convert(sourceEncode, TextEncoding.UTF8, sourceBytes);
     return(GenerateBytes(convertBytes));
 }
示例#6
0
        public byte[] Encoding(byte[] sourceBytes, TextEncoding sourceEncode)
        {
            var _encoding = TextEncoding.GetEncoding(EncodePageName);

            return(TextEncoding.Convert(sourceEncode, _encoding, sourceBytes));
        }
示例#7
0
        public byte[] Encoding(byte[] sourceBytes)
        {
            var encoding = TextEncoding.GetEncoding(EncodePageName);

            return(TextEncoding.Convert(TextEncoding.UTF8, encoding, sourceBytes));
        }
示例#8
0
        /// <summary>
        /// Converts a byte[] to a string.
        /// </summary>
        /// <param name="bytes">The bytes to convert.</param>
        /// <returns>The resulting string.</returns>
        private static string GetString(byte[] bytes)
        {
            var buffer = Encoding.Convert(Encoding.GetEncoding("iso-8859-1"), Encoding.UTF8, bytes);

            return(Encoding.UTF8.GetString(buffer, 0, bytes.Count()));
        }
示例#9
0
        private static string ReadContext(HttpContent context, bool databyte = false)
        {
            try
            { Console.WriteLine(context.Headers.ContentEncoding);
              if (context.Headers.ContentEncoding.Contains("ggggzip"))
              {
                  Console.WriteLine("DECODE GZIP");
                  var        responseStream = context.ReadAsStreamAsync().Result;
                  GZipStream ms;
                  var        stream = new System.IO.Compression.GZipStream(responseStream, System.IO.Compression.CompressionMode.Decompress);
              }


              if (databyte)
              {
                  var result = context.ReadAsByteArrayAsync().Result;

                  var encoding = Encoding.GetEncoding("windows-1251");
                  result = Encoding.Convert(encoding, Encoding.Default, result);
                  Console.WriteLine("RET DATABYTE ENC");
                  return(Encoding.Default.GetString(result));
              }
            }
            catch (Exception e)
            { }

            try
            {
                return(context.ReadAsStringAsync().Result);
            }
            catch (Exception e)
            {
                var result = context.ReadAsByteArrayAsync().Result;
                try
                {
                    var encoding = Encoding.Default;
                    result = Encoding.Convert(encoding, Encoding.Default, result);
                }
                catch
                {
                    try
                    {
                        var encoding = Encoding.GetEncoding(context.Headers.ContentType.CharSet);
                        result = Encoding.Convert(encoding, Encoding.Default, result);
                    }
                    catch
                    {
                        try
                        {
                            var encoding = Encoding.UTF8;
                            result = Encoding.Convert(encoding, Encoding.Default, result);
                        }
                        catch
                        {
                            try
                            {
                                var encoding = Encoding.ASCII;
                                result = Encoding.Convert(encoding, Encoding.Default, result);
                            }
                            catch
                            {
                                try
                                {
                                    var encoding = Encoding.Unicode;
                                    result = Encoding.Convert(encoding, Encoding.Default, result);
                                }
                                catch (Exception ex)
                                {
                                }
                            }
                        }
                    }
                }
                return(Encoding.Default.GetString(result));
            }
        }