title: Azure Mobile Services, HttpClient, Authorization
body: <p><strong>Can I use .NET's HttpClient to hit an Azure Mobile service?</strong></p>
  
  <p>How do I authenticate with the Mobile Service's own baked in <a href="http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-get-started-custom-authentication/">custom Authentication/Authorization patterns</a> with the HttpClient? </p>
  
  <p>This always returns 401, because I'm not passing in any authentication credentials:</p>
  
  <pre><code>var client = new HttpClient();           
  var response = client.GetAsync("http://localhost:49190/api/test").Result;
  </code></pre>
  
  <p>Furthermore, how come when I use the <a href="http://azure.microsoft.com/en-us/documentation/articles/mobile-services-html-how-to-use-client-library/">Mobile Service Client</a>, why does my application key, master key, or user auth key always return (401) Unauthorized? </p>
  
  <p>Client:</p>
  
  <pre><code>var mobileClient = new MobileServiceClient("http://localhost:49190/", "[my key]");
  var response = mobileClient.InvokeApiAsync("test").Result;
  </code></pre>
  
  <p>Service Side:</p>
  
  <pre><code>[AuthorizeLevel(AuthorizationLevel.Application)]
  public class TestController : ApiController
  {
      public ApiServices Services { get; set; }
  
      // GET api/Test
      public string Get()
      {
          Services.Log.Info("Hello from custom controller!");
          return "Hello";
      }
  }
  </code></pre>