0

How to preserve Basic Auth after redirecting in HttpClient?

Below is my code I use in Xamarin Forms. When I use the original URL, authentication works. But when I use the redirect URL, I get an "Unauthorized" response. The redirect URL works fine in Postman.

using (var client = new HttpClient())
{
    client.DefaultRequestHeaders.Add("email", TxtEmail.Text);
    client.DefaultRequestHeaders.Add("password", TxtPassword.Text);
    client.DefaultRequestHeaders.Authorization = HttpClientHelper.NdAuth;
    var result = await client.GetAsync(Constants.UrlLoginUser);
}

How to preserve Basic Auth while redirecting? How Postman is able to do it?

Heshan
  • 913
  • 8
  • 30
  • Take a look on this thread http://stackoverflow.com/questions/14627399/setting-authorization-header-of-httpclient it should give you an idea. – EvZ Mar 13 '17 at 19:22
  • @EvZ I'm using the correct way to set authorization. What I want to find is, why the authentication gets destroyed when re-directing? – Heshan Mar 14 '17 at 05:02
  • Same question have been asked already: http://stackoverflow.com/a/14056998/1970317 – EvZ Mar 14 '17 at 07:34
  • Yes. But it's different in Xamarin forms. Credential cache is not available. – Heshan Mar 14 '17 at 08:55

0 Answers0