Here is the code:
HttpClient client = null;
HttpClientHandler httpClientHandler = new HttpClientHandler()
{
Proxy = new WebProxy(string.Format("{0}:{1}", proxyServerSettings.Address,
proxyServerSettings.Port),false),
PreAuthenticate = true,
UseDefaultCredentials = false,
};
this.httpClientHandler.Credentials = new NetworkCredential(proxyServerSettings.UserName,
proxyServerSettings.Password);
this.client = new HttpClient(this.httpClientHandler);
And when I finally do this:
HttpResponseMessage httpResponseMessage = this.client.PostAsync(urlToPost, new StringContent(data, Encoding.UTF8, this.mediaType)).Result;
It always throws the
The remote server returned an error: (407) Proxy Authentication Required.
Which I do not understand for the world of me.
The same proxy set up works just fine when is configured in IE10 or if I use the HttpWebRequest
class instead