title: Pingdom restful API C#
body: <p>I am having trouble using Pingdoms API</p>
  
  <p>I have generated a key for my application and added it to the header of my request. But i keep getting a 401 errorcode :(</p>
  
  <pre><code>NetworkCredential nc = new NetworkCredential("my_email", "my_password", "httpS://api.pingdom.com/2.0/checks");
  CredentialCache cc = new CredentialCache();
  cc.Add("httpS://api.pingdom.com/2.0/checks", 443, "Basic", nc);
  
  HttpWebRequest request = HttpWebRequest)WebRequest.Create("httpS://api.pingdom.com/2.0/checks");
  request.Proxy = new WebProxy("my_proxy",true); //I'm behind a strict firewall...
  request.Headers.Add("App-Key", "my_appKey");
  request.ContentLength = 0;
  request.Credentials = cc;
  request.PreAuthenticate = true;
  request.Method = "POST";
  
  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  </code></pre>
  
  <p>Im pretty lost :(</p>
  
  <p>Whatever i do i get:</p>
  
  <pre><code>An unhandled exception of type 'System.Net.WebException' occurred in System.dll
  Additional information: The remote server returned an error: (401) Unauthorized.
  </code></pre>
  
  <p><em><strong>WORKING CODE</em></strong>
  Thanks to @Guy I got it to work! heres my working code for anyone strugling with the same problem</p>
  
  <pre><code>public class PingdomChecks
  {
      public List&lt;PingdomCheck&gt; Checks { get; set; }
  }
  
  public class PingdomCheck
  {
      public string ID { get; set; }
      public int Created { get; set; }
      public string Name { get; set; }
      public string Hostname { get; set; }
      public string Resolution { get; set; }
      public int LastErrorTime { get; set; }
      public int LastTestTime { get; set; }
      public int LastResponseTime { get; set; }
      public string Status { get; set; }
      public string[] Tags { get; set; }
  }
  
  public class Tools
  {
  
      public static void SetBasicAuthHeader(WebRequest request, String userName, String userPassword)
      {
          string authInfo = userName + ":" + userPassword;
          authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
          request.Headers["Authorization"] = "Basic " + authInfo;
      }
  
      public static void Pingdom()
      {
          HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.pingdom.com/api/2.0/checks");
          request.Headers.Add("App-Key", "YOUR_APP_KEY");
          request.ContentLength = 0;
          request.PreAuthenticate = true;
          request.Method = "GET";
          SetBasicAuthHeader(request, "YOUR_EMAIL", "YOUR_PASSWORD");
  
          HttpWebResponse response = (HttpWebResponse)request.GetResponse();
          var stream = response.GetResponseStream(); 
          var reader = new StreamReader(stream);
          var html = reader.ReadToEnd();
  
          PingdomCheck Checks = JsonConvert.DeserializeObject&lt;PingdomCheck&gt;(html);
      }
  </code></pre>
  
  <p>}</p>