本文整理汇总了C#中ASCIIEncoding类的典型用法代码示例。如果您正苦于以下问题:C# ASCIIEncoding类的具体用法?C# ASCIIEncoding怎么用?C# ASCIIEncoding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ASCIIEncoding类属于命名空间,在下文中一共展示了ASCIIEncoding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostHtmlFromUrl
/// <summary>
/// �����������վ��UTF-8���룬Http Post�������Ҳ��Ҫ��UTF-8����
/// HttpUtility.UrlEncode(merId, myEncoding)
/// </summary>
/// <param name="url">���ʵ�ַ����������</param>
/// <param name="para">�����ַ���</param>
/// <returns></returns>
public static string PostHtmlFromUrl(string url, string postData)
{
String sResult = "";
try
{
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(postData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
request.ContentLength = postData.Length;
Stream stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
return content;
}
catch (Exception e)
{
sResult = "-101";
return sResult;
}
}
示例2: Main
static int Main ()
{
HttpWebRequest request = (HttpWebRequest) WebRequest.Create ("http://localhost:8081/Default.aspx");
request.Method = "POST";
ASCIIEncoding ascii = new ASCIIEncoding ();
byte [] byData = ascii.GetBytes ("Mono ASP.NET");
request.ContentLength = byData.Length;
Stream rs = request.GetRequestStream ();
rs.Write (byData, 0, byData.Length);
rs.Flush ();
try {
HttpWebResponse response = (HttpWebResponse) request.GetResponse ();
using (StreamReader sr = new StreamReader (response.GetResponseStream (), Encoding.UTF8, true)) {
string result = sr.ReadToEnd ();
if (result.IndexOf ("<p>REQ:0</p>") == -1) {
Console.WriteLine (result);
return 1;
}
}
response.Close ();
} catch (WebException ex) {
if (ex.Response != null) {
StreamReader sr = new StreamReader (ex.Response.GetResponseStream ());
Console.WriteLine (sr.ReadToEnd ());
} else {
Console.WriteLine (ex.ToString ());
}
return 2;
}
return 0;
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string url = "https://graph.facebook.com/567517451/notifications";
HttpWebRequest httpWReq =
(HttpWebRequest)WebRequest.Create(url);
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "access_token=355242331161855|qyYMEnPyR2y3sWK8H7rN-6n3lBU";
postData += "&template=Test";
postData += "&href=http://postaround.me";
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();
}
示例4: Main
public static void Main()
{
try {
TcpClient tcpclnt = new TcpClient();
//Console.WriteLine("Connecting.....");
tcpclnt.Connect("161.115.86.57",8001);
// use the ipaddress as in the server program
//Console.WriteLine("Connected");
//Console.Write("Enter the string to be transmitted : ");
String sendString = Console.ReadLine();
Stream serverSendStream = tcpclnt.GetStream();
ASCIIEncoding asen = new ASCIIEncoding();
byte[] bytesInSend = asen.GetBytes(sendString);
//Console.WriteLine("Transmitting.....");
// send length then string to read to length+1
serverSendStream.Write(bytesInSend, 0, bytesInSend.Length);
byte[] bytesToRead = new byte[100];
int numberOfBytesRead = serverSendStream.Read(bytesToRead, 0, bytesToRead.Length);
for (int i = 0; i < numberOfBytesRead; i++)
Console.Write(Convert.ToChar(bytesToRead[i]));
tcpclnt.Close();
}
catch (Exception e) {
Console.WriteLine("Error..... " + e.StackTrace);
}
}
示例5: OnActivate
public static bool OnActivate()
{
encoding = new ASCIIEncoding();
InitializeComponents();
installerForm.ShowDialog();
if (installSelected == false)
return false;
if (! InstallModuleCore())
return false;
if (cyberwareSelected) {
if (! InstallModuleCyberware())
return false;
}
if (equipmentSelected) {
if (! InstallModuleEquipment())
return false;
}
if (rebalanceSelected) {
if (! InstallModuleRebalance())
return false;
}
return true;
}
示例6: CutString
/// <summary>
/// 截取字符长度
/// </summary>
/// <param name="inputString">字符</param>
/// <param name="len">长度</param>
/// <returns></returns>
public static string CutString(string inputString, int len)
{
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;
}
示例7: KalimbaPdImplNetwork
public KalimbaPdImplNetwork()
{
asciiEncoding = new ASCIIEncoding();
t = new Thread(NetworkRun);
t.Start();
}
示例8: Main
public static void Main()
{
try
{
TcpListener Listener;
Socket client_socket;
acceptconnection(out Listener, out client_socket);
Receive(client_socket);
//int gh = testReceive(client_socket);
ASCIIEncoding asen = new ASCIIEncoding();
client_socket.Send(asen.GetBytes("The string was recieved by the server."));
Console.WriteLine("\nSent Acknowledgement");
client_socket.Close();
Listener.Stop();
}
catch (Exception error)
{
Console.WriteLine("Error..... " + error.StackTrace);
}
}
示例9: DoNegAOORTest
private void DoNegAOORTest(ASCIIEncoding ascii, int charCount)
{
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
ascii.GetMaxByteCount(charCount);
});
}
示例10: DoPosTest
private void DoPosTest(ASCIIEncoding ascii, string source, int charIndex, int count, byte[] bytes, int byteIndex)
{
int actualValue;
actualValue = ascii.GetBytes(source, charIndex, count, bytes, byteIndex);
Assert.True(VerifyASCIIEncodingGetBytesResult(ascii, source, charIndex, count, bytes, byteIndex, actualValue));
}
示例11: sendMessage
public static void sendMessage(Socket clientSocket)
{
ASCIIEncoding asn = new ASCIIEncoding();
String sendString = Console.ReadLine();
//String sendString = "This is a test!!!!!!!!!!!!!!!!!!!!!!!!";
clientSocket.Send(asn.GetBytes(sendString));
}
示例12: RunTest
static void RunTest ()
{
// Start the server thread
ServerThread serverThread = new ServerThread ();
serverThread.Start ();
// Create the client
HttpWebRequest rq = (HttpWebRequest) WebRequest.Create ("http://" + IPAddress.Loopback.ToString () + ":54321");
rq.ProtocolVersion = HttpVersion.Version11;
rq.KeepAlive = false;
// Get the response
HttpWebResponse rsp = (HttpWebResponse) rq.GetResponse ();
ASCIIEncoding enc = new ASCIIEncoding ();
StringBuilder result = new StringBuilder ();
// Stream the body in 1 byte at a time
byte [] bytearr = new byte [1];
Stream st = rsp.GetResponseStream ();
while (true) {
int b = st.Read (bytearr, 0, 1);
if (b == 0) {
break;
}
result.Append (enc.GetString (bytearr));
}
Assert.AreEqual ("012345670123456789abcdefabcdefghijklmnopqrstuvwxyz",
result.ToString (), "#1");
}
示例13: DoPosTest
private void DoPosTest(ASCIIEncoding ascii, int byteCount, int expectedValue)
{
int actualValue;
ascii = new ASCIIEncoding();
actualValue = ascii.GetMaxCharCount(byteCount);
Assert.Equal(expectedValue, actualValue);
}
示例14: echoMessage
public static int echoMessage(Socket clientSocket)
{
string messageToSend = testReceive(clientSocket);
ASCIIEncoding asn = new ASCIIEncoding();
clientSocket.Send(asn.GetBytes(messageToSend));
return messageToSend.Length;
}
示例15: TryConnect
//пытаемся отправить кому-то сообщение о том, что хотим понаблюдать за его игрой
//если прокатывает - в ответ нам начнут приходить сообщения о состоянии игры
public void TryConnect(string ip, string port)
{
try
{
TcpClient tcpclnt = new TcpClient();
tcpclnt.Connect(IPAddress.Parse(ip), int.Parse(port));
String str = Dns.GetHostByName(Dns.GetHostName()).AddressList[0].ToString();
Stream stm = tcpclnt.GetStream();
ASCIIEncoding asen = new ASCIIEncoding();
byte[] ba = asen.GetBytes(str);
stm.Write(ba, 0, ba.Length);
byte[] bb = new byte[255];
int k = stm.Read(bb, 0, 255);
string an = "";
for (int i = 0; i < k; i++)
an += Convert.ToChar(bb[i]);
stm.Close();
tcpclnt.Close();
}
catch (Exception e)
{
Debug.LogError(e.StackTrace);
}
}