Код: Выделить всё
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Collections;
using System.Web;
/** @class TCToken
* An example class for generating a TrustCommerce Trustee Token
*/
public class TCToken
{
public static void Main(string [] args)
{
string custid = "123456";
string password = "XXXXXX";
try {
// Adapted from http://www.west-wind.com/presentations/dotnetWebRequest/dotnetWebRequest.htm
string gateway_post_address = "https://vault.trustcommerce.com/trustee/token.php";
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(gateway_post_address);
// A sixty second timeout.
req.Timeout = 60000;
string post_data = "custid=" + HttpUtility.UrlEncode(custid) +
"&password=" + HttpUtility.UrlEncode(password);
req.Method = "POST";
byte [] buf = System.Text.Encoding.GetEncoding(1252).GetBytes(post_data);
req.ContentLength = buf.Length;
req.ContentType = "application/x-www-form-urlencoded";
Stream s = req.GetRequestStream();
s.Write(buf, 0, buf.Length);
s.Close();
HttpWebResponse rep = (HttpWebResponse) req.GetResponse();
Encoding enc = System.Text.Encoding.GetEncoding(1252);
StreamReader rs = new StreamReader(rep.GetResponseStream(), enc);
string token = rs.ReadToEnd();
Console.WriteLine(token);
rep.Close();
rs.Close();
} catch (Exception e) {
Console.WriteLine(e);
}
}
}
System.NotSupportedException: данные для кодировки 1252 недоступны.
Информацию об определении пользовательской кодировки см. в документации
метода Encoding.RegisterProvider. at
System.Text.Encoding.GetEncoding(кодовая страница Int32) at
TCToken.Program.Main(String[] args) в
C:\Users\xxxx\source\repos\TCToken\ TCToken\Program.cs:строка 29
Я пытался найти в Google эту ошибку, но большинство ответов немного выше моего понимания. Я определенно не эксперт по C#.
Подробнее здесь: https://stackoverflow.com/questions/508 ... oding-1252