title: 401 Unauthorized when calling Stormpath REST API with WebRequest object?
body: <p>I am using Stormpath for my authentication service. I call the RestAPI of Stormpath by using HttpWebRequest.</p>
  
  <p>I am also using HttpWebRequest to call the RestAPI but it does not work.</p>
  
  <pre><code>private void BtnGetResetApiClick(object sender, EventArgs e)
  {
  
  var username = "aaaa";
  var password = "bbbb";
  ServicePointManager.ServerCertificateValidationCallback = Callback;
  var request = WebRequest.Create("https://api.stormpath.com/v1/tenants/current") as HttpWebRequest;
  
  request.UserAgent = ".NET SDK";
  request.Method = "GET";
  request.Accept = "*/*";
  
  var data = string.Format("{0}:{1}", username, HttpUtility.HtmlEncode(password));
  
  var token = Convert.ToBase64String(Encoding.UTF8.GetBytes(data));
  string authHeader = string.Format("Basic {0}", token);
  
  request.Headers.Add("Authorization", authHeader);
  request.ServerCertificateValidationCallback = Callback;
  
  using (var response = request.GetResponse())
  {
      var stream = response.GetResponseStream();
      if (stream != null)
      {
          var streamReader = new StreamReader(stream);
          var str = streamReader.ReadToEnd();
          streamReader.Close();
          stream.Close();
      }
    }
  }
  
  private bool Callback(object obj, X509Certificate certificate, X509Chain  chain, SslPolicyErrors errors)
  {
   return true;
  }
  </code></pre>
  
  <p>When calling:</p>
  
  <pre><code>var response = request.GetResponse()
  </code></pre>
  
  <p>I got an exception:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.Net.WebException' occurred in System.dll The remote server returned an error: (401) Unauthorized.</p>
  </blockquote>
  
  <p>Can you help me to see if my code has something wrong?</p>