C# .. API httpclient authentication and proxy with username and password

Viewed 8717

I'm new in API's world but I had a question, I want to get data from Web API but there's two authentication

  • First with proxy.
  • Second with API base authentication.

here's my Get Action code:

        HttpClientHandler handler = new HttpClientHandler();
        handler.Credentials = new NetworkCredential("test", "testing");
        HttpClient client = new HttpClient(handler);
        client.BaseAddress = new Uri("http://test.abctesting.com/");
        client.DefaultRequestHeaders.Accept.Clear();
        client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.
            MediaTypeWithQualityHeaderValue("application/json"));

        HttpResponseMessage response = client.GetAsync("admin/apiv2/").Result;
        var tenders = response.Content.ReadAsAsync<tenders>().Result;

this code work fine with me but just in pass over proxy username and password! How can I continue to Get API Data with authentication username and password?

2 Answers
Related