title: How to consume Web API Restful webservices with Forms Authentication from a Console Application?
body: <p>I have the following function declared in a web API controller. IIS Server is configured for the Web API to use Forms Authentication (can't enable Basic authentication due to customer restrictions):</p>
  
  <pre><code>[HttpGet]
  [Authorize]
  [Route("")]
  public ContactDTO GetPharmacy()
  {
      return ToContactDTO(customerContext.CurrentContact);
  }
  </code></pre>
  
  <p>Using this service as a logged user from a webbrowser using Jquery Ajax ($.ajax(...)) works fine and perfectly. However I want to do the same thing using the HttpClient class from .Net. I tried the following, yet without any success, always getting a 401 Unathorized response.</p>
  
  <pre><code>using (var client = new HttpClient())
  {
       client.BaseAddress = new Uri("http://localhost:17200");
  
       AuthenticationHeaderValue authHeader = new AuthenticationHeaderValue("Forms", Convert.ToBase64String(new ASCIIEncoding().GetBytes(String.Format("{0}:{1}", "admin", "123456"))));
       client.DefaultRequestHeaders.Authorization = authHeader;
       client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
       HttpResponseMessage response = client.GetAsync("/api/pharmacies").Result;
  }
  </code></pre>
  
  <p>How should I use the HttpClient to work with forms Authentication?</p>
  
  <p>Thank you.</p>