title: how do i get a bearer token in a .Net console application?
body: <p>I was following <a href="http://www.asp.net/web-api/overview/security/individual-accounts-in-web-api" rel="nofollow">this</a> tutorial about how to authorize and get a bearer token from a web-api server. The tasks performed there through fiddler are pretty simple, but, when I tried to do the same from a console application the request fails with a <code>400 Bad Request Error</code>. Here is the code that makes the request to the server:</p>
  
  <pre><code>var request = WebRequest.Create("http://localhost:12698/token") as HttpWebRequest;
      request.Method = "POST";
      request.ContentType = "application/x-www-form-urlencoded";
      request.CookieContainer = new CookieContainer();         
      var authCredentials = "userName=" + user + "&amp;password=" + password;
      byte[] bytes = System.Text.Encoding.UTF8.GetBytes(authCredentials);
      request.ContentLength = bytes.Length;
      using (var requestStream = request.GetRequestStream()){
          requestStream.Write(bytes, 0, bytes.Length);
      }
  
      using (var response = request.GetResponse() as HttpWebResponse){
          authCookie = response.Cookies["access_token"];
      }
  </code></pre>
  
  <p>can someone help me in determining what I am doing wrong here? or is there some other approach I should use to get the authentication token?</p>