title: System.NotSupportedException: No data is available for encoding 1252
body: <p>I'm working with a <a href="https://vault.trustcommerce.com/" rel="noreferrer">Trust Commerce Tutorial</a> on how to generate a payment token that will allow customers to use the TC Trustee Host payment form. I was given an example on how to retrieve this token by their dev team.</p>
  <pre><code>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 = &quot;123456&quot;;
          string password = &quot;XXXXXX&quot;;
          try {
              // Adapted from http://www.west-wind.com/presentations/dotnetWebRequest/dotnetWebRequest.htm
              string gateway_post_address = &quot;https://vault.trustcommerce.com/trustee/token.php&quot;;
              HttpWebRequest req = (HttpWebRequest) WebRequest.Create(gateway_post_address);
  
              // A sixty second timeout.
              req.Timeout = 60000;
  
              string post_data = &quot;custid=&quot; + HttpUtility.UrlEncode(custid) +
                                  &quot;&amp;password=&quot; + HttpUtility.UrlEncode(password);
              
              req.Method = &quot;POST&quot;;
              byte [] buf = System.Text.Encoding.GetEncoding(1252).GetBytes(post_data);
              req.ContentLength = buf.Length;
              req.ContentType = &quot;application/x-www-form-urlencoded&quot;;
  
              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);
          }
      }
  }
  </code></pre>
  <p>I made a new console application in visual studio, copied this code, and replaced the username and password with the correct credentials. When I try to run this, I get the following error in the console.</p>
  <blockquote>
  <p>System.NotSupportedException: No data is available for encoding 1252.
  For information on defining a custom encoding, see the documentation
  for the Encoding.RegisterProvider method.    at
  System.Text.Encoding.GetEncoding(Int32 codepage)    at
  TCToken.Program.Main(String[] args) in
  C:\Users\xxxx\source\repos\TCToken\TCToken\Program.cs:line 29</p>
  </blockquote>
  <p>I've tried to google this error and most of the responses are a little above my understanding. I'm certainly not a C# expert.</p>