当前位置: 首页>>代码示例>>C#>>正文


C# Text.ASCIIEncoding类代码示例

本文整理汇总了C#中System.Text.ASCIIEncoding的典型用法代码示例。如果您正苦于以下问题:C# ASCIIEncoding类的具体用法?C# ASCIIEncoding怎么用?C# ASCIIEncoding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ASCIIEncoding类属于System.Text命名空间,在下文中一共展示了ASCIIEncoding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MakeRequest

        public static string MakeRequest(string url, object data) {

            var ser = new JavaScriptSerializer();
            var serialized = ser.Serialize(data);
            
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Method = "POST";
            //request.ContentType = "application/json; charset=utf-8";
            //request.ContentType = "text/html; charset=utf-8";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = serialized.Length;


            /*
            StreamWriter writer = new StreamWriter(request.GetRequestStream());
            writer.Write(serialized);
            writer.Close();
            var ms = new MemoryStream();
            request.GetResponse().GetResponseStream().CopyTo(ms);
            */


            //alternate method
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] byte1 = encoding.GetBytes(serialized);
            Stream newStream = request.GetRequestStream();
            newStream.Write(byte1, 0, byte1.Length);
            newStream.Close();



            
            return serialized;
        }
开发者ID:GoogleFrog,项目名称:Zero-K-Infrastructure,代码行数:35,代码来源:JsonRequest.cs

示例2: connect

 //Connect to the client
 public void connect()
 {
     if (!clientConnected)
     {
         IPAddress ipAddress = IPAddress.Any;
         TcpListener listener = new TcpListener(ipAddress, portSend);
         listener.Start();
         Console.WriteLine("Server is running");
         Console.WriteLine("Listening on port " + portSend);
         Console.WriteLine("Waiting for connections...");
         while (!clientConnected)
         {
             s = listener.AcceptSocket();
             s.SendBufferSize = 256000;
             Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);
             byte[] b = new byte[65535];
             int k = s.Receive(b);
             ASCIIEncoding enc = new ASCIIEncoding();
             Console.WriteLine("Received:" + enc.GetString(b, 0, k) + "..");
             //Ensure the client is who we want
             if (enc.GetString(b, 0, k) == "hello" || enc.GetString(b, 0, k) == "hellorcomplete")
             {
                 clientConnected = true;
                 Console.WriteLine(enc.GetString(b, 0, k));
             }
         }
     }
 }
开发者ID:kartikeyadubey,项目名称:share,代码行数:29,代码来源:Server.cs

示例3: sendSMS

        public String sendSMS(String to_phonenumber, String message)
        {
            //return "";
            String url = "https://rest.nexmo.com/sms/json";
            String postData = "";

            HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(url);

            ASCIIEncoding encoding = new ASCIIEncoding();

            postData += "api_key=" + Configs.SMS_API_KEY;
            postData += "&api_secret=" + Configs.SMS_API_SECRET;
            postData += "&from=" + "Logic+Uni";
            postData += "&to=" + to_phonenumber;
            postData += "&text=" + message;

            byte[] data = encoding.GetBytes(postData);

            httpWReq.Method = "POST";
            httpWReq.ContentType = "application/x-www-form-urlencoded";
            httpWReq.ContentLength = data.Length;

            using (Stream stream = httpWReq.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();

            string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            return responseString;
        }
开发者ID:TheinHtikeAung,项目名称:Stationery-Store-Inventory-System,代码行数:32,代码来源:SMSController.cs

示例4: Encode

 public static string Encode(string value)
 {
     var hash = System.Security.Cryptography.MD5.Create();
     var encoder = new System.Text.ASCIIEncoding();
     var combined = encoder.GetBytes(value ?? string.Empty);
     return BitConverter.ToString(hash.ComputeHash(combined)).ToLower().Replace("-", string.Empty);
 }
开发者ID:Aldonei,项目名称:Stefanini,代码行数:7,代码来源:MD5.cs

示例5: sendMessageTo

 public void sendMessageTo(string message)
 {
     System.Text.ASCIIEncoding encode = new System.Text.ASCIIEncoding();
     string sendstring = message;
     byte[] sendData = encode.GetBytes(sendstring);
     server.Send(sendData, sendData.Length, clientAdress, clientPort);
 }
开发者ID:Achanigo,项目名称:Multiplayer_Shooter,代码行数:7,代码来源:Server.cs

示例6: SendMessage

        public void SendMessage(string message)
        {
            try
            {
                var baseAddress = "http://79.124.67.13:8080/activities";

                var http = (HttpWebRequest)WebRequest.Create(new Uri(baseAddress));
                http.Accept = "application/json";
                http.ContentType = "application/json";
                http.Method = "POST";

                string parsedContent = "{\"content\":\"" + message + "\"}";
                ASCIIEncoding encoding = new ASCIIEncoding();
                Byte[] bytes = encoding.GetBytes(parsedContent);

                Stream newStream = http.GetRequestStream();
                newStream.Write(bytes, 0, bytes.Length);
                newStream.Close();

                var response = http.GetResponse();
                var stream = response.GetResponseStream();
                var sr = new StreamReader(stream);
                var content = sr.ReadToEnd();
            }
            catch (Exception ex) {
                // File.WriteAllText(@"C:\Temp\ex.txt", ex.ToString());
            }
        }
开发者ID:NasaSpaceAppsChallenge2014,项目名称:NasaAstroPlatform,代码行数:28,代码来源:NasaMessageSenderService.cs

示例7: Authenticate

        public XDocument Authenticate(string username, string password)
        {
            ASCIIEncoding enc = new ASCIIEncoding ();

            if (_stream == null || !_stream.CanRead)
                this.GetStream ();

            this.Username = username;
            this.Password = password;

            XDocument authXML = new XDocument (
                                    new XElement ("authenticate",
                                        new XElement ("credentials",
                                            new XElement ("use" +
                                            "rname", username),
                                            new XElement ("password", password)
                                        )));

            this.Stream.Write (enc.GetBytes (authXML.ToString ()));

            string response = ReadMessage (this.Stream);

            XDocument doc = XDocument.Parse (response);

            if (doc.Root.Attribute ("status").Value != "200")
                throw new Exception ("Authentication failed");

            return doc;
        }
开发者ID:Nusec,项目名称:gray_hat_csharp_code,代码行数:29,代码来源:OpenVASSession.cs

示例8: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            string strId = textUserId.Text;
            string strName = textTitle.Text;

            ASCIIEncoding encoding = new ASCIIEncoding();
            string postData = "user_id=" + strId;
            postData += ("&title=" + strName);
            MyWebRequest My = new MyWebRequest("http://zozatree.herokuapp.com/api/titles", "POST", postData);
            string HtmlResult = My.GetResponse();
            //wc.Headers["Content-type"] = "application/x-www-form-urlencoded";

            //string HtmlResult = wc.UploadString(URL, myParamters);

            string bodySeparator = "{";
            string[] stringSeparators = new string[] { bodySeparator };
            string[] splitBodey = HtmlResult.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);
            List<UserBO> u = new List<UserBO>();
            foreach (string item in splitBodey)
            {
                UserBO b = new UserBO(item.Replace("}",""));
                u.Add(b);
                if (b.UserId != -1)
                    labResponse.Text += b.toString();
            }
        }
开发者ID:bechor,项目名称:ZozaTreeClient,代码行数:26,代码来源:Form1.cs

示例9: Chr

 //ASCII 码转字符
 public static string Chr(int asciiCode)
 {
     System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
                     byte[] byteArray = new byte[] { (byte)asciiCode };
                     string strCharacter = asciiEncoding.GetString(byteArray);
                     return (strCharacter);
 }
开发者ID:Strongc,项目名称:sencond,代码行数:8,代码来源:ZkdBpSap.cs

示例10: Hash

        public static uint Hash(string data)
        {
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            byte[] bytes = encoding.GetBytes(data);

            return Hash(ref bytes);
        }
开发者ID:xoperator,项目名称:GoKapara,代码行数:7,代码来源:Jenkins96.cs

示例11: GenKey

        static void GenKey(string baseName, out byte[] desKey, out byte[] desIV)
        {
            byte[] secretBytes = { 6, 29, 66, 6, 2, 68, 4, 7, 70 };

            byte[] baseNameBytes = new ASCIIEncoding().GetBytes(baseName);

            byte[] hashBytes = new byte[secretBytes.Length + baseNameBytes.Length];

            // copy secret byte to start of hash array
            for (int i = 0; i < secretBytes.Length; i++)
            {
                hashBytes[i] = secretBytes[i];
            }

            // copy filename byte to end of hash array
            for (int i = 0; i < baseNameBytes.Length; i++)
            {
                hashBytes[i + secretBytes.Length] = baseNameBytes[i];
            }

            SHA1Managed sha = new SHA1Managed();

            // run the sha1 hash
            byte[] hashResult = sha.ComputeHash(hashBytes);

            desKey = new byte[8];
            desIV = new byte[8];

            for (int i = 0; i < 8; i++)
            {
                desKey[i] = hashResult[i];
                desIV[i] = hashResult[8 + i];
            }
        }
开发者ID:ufosky-server,项目名称:MultiversePlatform,代码行数:34,代码来源:Program.cs

示例12: Main

        static void Main(string[] args)
        {
            Console.WriteLine("MD5 und SHA Beispiel");
            Console.WriteLine("====================");

            //Eingabe lesen und in ein Byte-Array verwandeln
            var bytes = new ASCIIEncoding().GetBytes(Input());

            //MD5
            var md5 = new MD5Cng();
            string md5Hash = BitConverter.ToString(md5.ComputeHash(bytes)).Replace("-", "").ToLower();
            Console.WriteLine("MD5-Hash:\t{0}", md5Hash);

            //SHA1
            var sha1Cng = new SHA1Cng();
            string sha1Hash = BitConverter.ToString(sha1Cng.ComputeHash(bytes)).Replace("-","").ToLower();
            Console.WriteLine("SHA1-Hash:\t{0}", sha1Hash);

            //SHA256
            var sha256 = new SHA256Cng();
            string sha256Hash = BitConverter.ToString(sha256.ComputeHash(bytes)).Replace("-", "").ToLower();
            Console.WriteLine("SHA256-Hash:\t{0}", sha256Hash);

            Console.WriteLine("Beliebige Taste drücken zum beenden");
            Console.ReadKey();
        }
开发者ID:christianaschoff,项目名称:Passworte-Teil2-md5sha,代码行数:26,代码来源:Program.cs

示例13: GetResponseFromServer

        private string GetResponseFromServer(string input)
        {
            var result = string.Empty;

            using (TcpClient client = new TcpClient())
            {
                client.Connect("127.0.0.1", 1234);
                var stream = client.GetStream();

                ASCIIEncoding ascii = new ASCIIEncoding();
                byte[] inputBytes = ascii.GetBytes(input.ToCharArray());

                stream.Write(inputBytes, 0, inputBytes.Length);

                byte[] readBytes = new byte[100];
                var k = stream.Read(readBytes, 0, 100);

                for (int i = 0; i < k; i++)
                {
                    result += Convert.ToChar(readBytes[i]);
                }

                client.Close();
            }

            return result;
        }
开发者ID:deyantodorov,项目名称:TelerikAcademy,代码行数:27,代码来源:ActualPriceProxy.cs

示例14: CutString

        /// <summary>
        /// 截取字符长度
        /// </summary>
        /// <param name="inputString">字符</param>
        /// <param name="len">长度</param>
        /// <returns></returns>
        public static string CutString(string inputString, int len)
        {
            if (string.IsNullOrEmpty(inputString))
                return "";
            inputString = DropHTML(inputString);
            ASCIIEncoding ascii = new ASCIIEncoding();
            int tempLen = 0;
            string tempString = "";
            byte[] s = ascii.GetBytes(inputString);
            for (int i = 0; i < s.Length; i++) {
                if ((int)s[i] == 63) {
                    tempLen += 2;
                } else {
                    tempLen += 1;
                }

                try {
                    tempString += inputString.Substring(i, 1);
                } catch {
                    break;
                }

                if (tempLen > len)
                    break;
            }
            //如果截过则加上半个省略号
            byte[] mybyte = System.Text.Encoding.Default.GetBytes(inputString);
            if (mybyte.Length > len)
                tempString += "…";
            return tempString;
        }
开发者ID:eyren,项目名称:OScms,代码行数:37,代码来源:Utils.cs

示例15: CryptString

        public static string CryptString(string val)
        {
            TripleDESCryptoServiceProvider dprov = new TripleDESCryptoServiceProvider();

            dprov.BlockSize = 64;
            dprov.KeySize = 192;
            byte[] IVBuf = BitConverter.GetBytes(DESIV);
            byte[] keyBuf = new byte[24];
            byte[] keyB0 = BitConverter.GetBytes(DESkey[0]);
            byte[] keyB1 = BitConverter.GetBytes(DESkey[1]);
            byte[] keyB2 = BitConverter.GetBytes(DESkey[2]);
            for (int i = 0; i < 8; i++) keyBuf[i] = keyB0[i];
            for (int i = 0; i < 8; i++) keyBuf[i + 8] = keyB1[i];
            for (int i = 0; i < 8; i++) keyBuf[i + 16] = keyB2[i];

            ICryptoTransform ict = dprov.CreateEncryptor(keyBuf, IVBuf);

            System.IO.MemoryStream mstream = new System.IO.MemoryStream();
            CryptoStream cstream = new CryptoStream(mstream, ict, CryptoStreamMode.Write);

            byte[] toEncrypt = new ASCIIEncoding().GetBytes(val);

            // Write the byte array to the crypto stream and flush it.
            cstream.Write(toEncrypt, 0, toEncrypt.Length);
            cstream.FlushFinalBlock();

            byte[] ret = mstream.ToArray();

            cstream.Close();
            mstream.Close();

            return Convert.ToBase64String(ret);
        }
开发者ID:bneuhold,项目名称:EFQM,代码行数:33,代码来源:Encryption64Util.cs


注:本文中的System.Text.ASCIIEncoding类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。