• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Text.ASCIIEncoding类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: GetLessonDownloadLink

        public string GetLessonDownloadLink(Lesson lesson)
        {
            var postdata = string.Format(@"{{a:""{0}"", m:""{1}"", course:""{2}"", cn:{3}, mt:""mp4"", q:""1024x768"", cap:false, lc:""en""}}",
                lesson.Author, lesson.Module.Name, lesson.Module.Course.Name, lesson.Number);

            var tempUri = new Uri(_lessonDownloadUrl);

            var encoding = new ASCIIEncoding();
            var data = encoding.GetBytes(postdata);

            var request = HttpWebRequest.Create(tempUri) as HttpWebRequest;

            request.Method = "POST";
            request.ContentType = "application/json;charset=UTF-8";
            request.ContentLength = data.Length;

            request.CookieContainer = _cookieContainer;

            var newStream = request.GetRequestStream();
            newStream.Write(data, 0, data.Length);
            newStream.Close();

            var responseHtml = request.GetResponse();

            var r = new StreamReader(responseHtml.GetResponseStream());
            return r.ReadToEnd();
        }
开发者ID:bogusgithubuser,项目名称:PluralsightDownloader,代码行数:27,代码来源:WebScraper.cs


示例17: HandleConnection

        public void HandleConnection(object state)
        {
            int recv = 1;
              byte[] data = new byte[1024];

              TcpClient client = threadListener.AcceptTcpClient();
              Stream ns = client.GetStream();
              try {
            connections++;
            Console.WriteLine("new Client: Currently {0} active connections", connections);
            ASCIIEncoding encoder = new ASCIIEncoding();
            string welcome = "Welcome";
            data = encoder.GetBytes(welcome);
            ns.Write(data, 0, welcome.Length);

            while (encoder.GetString(data, 0, recv) != "Close") {
              data = new byte[1024];
              recv = ns.Read(data, 0, data.Length);
              Console.WriteLine("Client: " + encoder.GetString(data, 0, recv));
            }
              }
              finally {
            ns.Close();
            client.Close();
            connections--;
            Console.WriteLine("Client disconnected: Currently {0} active connections", connections);
              }
        }
开发者ID:AlternateIf,项目名称:ShortcutDevice,代码行数:28,代码来源:Server.cs


示例18: NachrichtAnAlle

        public void NachrichtAnAlle(ArrayList b, string Nachricht)
        {
            //dringend bearbeiten

            while (true)
            {
                try
                {
                    foreach (Server.extended y in b)
                    {
                        try
                        {
                            NetworkStream clientStream = y.tcp.GetStream();
                            ASCIIEncoding encoder = new ASCIIEncoding();
                            byte[] buffer = encoder.GetBytes(Nachricht);

                            clientStream.Write(buffer, 0, buffer.Length);
                            clientStream.Flush();

                        }
                        catch
                        {
                            b.Remove(y);
                        }

                    }
                    break;
                }
                catch
                {
                }
            }
        }
开发者ID:ninja2009,项目名称:OVEYE-SERVER,代码行数:33,代码来源:Class1.cs


示例19: Post

        public string Post(string url, Dictionary<string, string> postData)
        {
            StringBuilder requestUrl = new StringBuilder(url);

            StringBuilder postDataStringBuilder = new StringBuilder();
            foreach (string key in postData.Keys)
            {
                postDataStringBuilder.AppendFormat("{0}={1}&", key, postData[key]);
            }
            string postDataString = postDataStringBuilder.ToString();

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl.ToString());

            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] b = encoding.GetBytes(postDataString);
            request.UserAgent = "Mozilla/4.0";
            request.Method = "POST";
            request.CookieContainer = _cookieContainer;
            request.ContentLength = b.Length;
            request.ContentType = "application/x-www-form-urlencoded";

            using (Stream stream = request.GetRequestStream())
            {
                stream.Write(b, 0, b.Length);
            }

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            string content = string.Empty;
            using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
            {
                content = streamReader.ReadToEnd();
                _cookieContainer.Add(response.Cookies);
            }
            return content;
        }
开发者ID:doaspx,项目名称:httpTool,代码行数:35,代码来源:HttpClient.cs


示例20: WriteToLog

        internal static void WriteToLog(SPWeb web, string message)
        {
            ASCIIEncoding enc = new ASCIIEncoding();
            UnicodeEncoding uniEncoding = new UnicodeEncoding();

            string errors = message;

            SPFile files = web.GetFile("/" + DocumentLibraryName + "/" + LogFileName);

            if (files.Exists)
            {
                byte[] fileContents = files.OpenBinary();
                string newContents = enc.GetString(fileContents) + Environment.NewLine + errors;
                files.SaveBinary(enc.GetBytes(newContents));
            }
            else
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    using (StreamWriter sw = new StreamWriter(ms, uniEncoding))
                    {
                        sw.Write(errors);
                    }

                    SPFolder LogLibraryFolder = web.Folders[DocumentLibraryName];
                    LogLibraryFolder.Files.Add(LogFileName, ms.ToArray(), false);
                }
            }

            web.Update();
        }
开发者ID:JoJo777,项目名称:TTK.SP,代码行数:31,代码来源:Logging.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Text.Decoder类代码示例发布时间:2022-05-26
下一篇:
C# ServiceProcess.ServiceProcessInstaller类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap