title: .net core 2.0 proxy requests always result in http 407 (Proxy Authentication Required)
body: <p>I'm trying to make HTTP requests via a WebProxy in a .net core 2.0 web application. The code I've got works fine in .net framework so I know (believe) its not an environmental issue. I've also tried to make the request using both <code>HttpWebRequest</code> and <code>HttpClient</code> but both mechanisms always result in 407 (Proxy Authentication Required) http error in .net core. Its as if in .net core the credentials I'm supplying are always being ignored.</p>
  
  <p>Here is the code I've been using:</p>
  
  <pre><code>public void Test() 
  {
      var cred = new NetworkCredential("xxxxx", "yyyyyy");
      var proxyURI = new Uri("http://xxx.xxx.xxx.xxx:80");
      var destinationURI = new Uri("http://www.bbc.co.uk");
      WebProxy proxy = new WebProxy(proxyURI, false) { UseDefaultCredentials = false, Credentials = cred };
  
      MakeProxyRequestViaHttpWebRequest(proxy, destinationURI);
      MakeProxyRequestViaHttpClient(proxy, destinationURI);
  }
  
  private void MakeProxyRequestViaHttpClient(WebProxy proxy, Uri destination)
  {
      HttpClientHandler handler = new HttpClientHandler()
      {
          Proxy = proxy,
          UseProxy = true,
          PreAuthenticate = true,
          UseDefaultCredentials = false
      };
  
      HttpClient client = new HttpClient(handler);
      HttpResponseMessage response = client.GetAsync(destination).Result;
      if (response.IsSuccessStatusCode)
      {
          HttpContent content = response.Content;
          string htmlData = content.ReadAsStringAsync().Result;
      }
      else
      {
          HttpStatusCode code = response.StatusCode;
      }
  }
  
  private void MakeProxyRequestViaHttpWebRequest(WebProxy proxy, Uri destination)
  {
      HttpWebRequest req = HttpWebRequest.Create(destination) as HttpWebRequest;
      req.UseDefaultCredentials = false;
      req.Proxy = proxy;
      req.PreAuthenticate = true;
  
      using (WebResponse response = req.GetResponse())
      {
          using (StreamReader responseStream = new StreamReader(response.GetResponseStream()))
          {
              string htmlData = responseStream.ReadToEnd();
          }
      }
  }
  </code></pre>
  
  <p>I've tried the following in .net core but the result is always 407:</p>
  
  <ol>
  <li>Run the code in a console app</li>
  <li>Implement IWebProxy and use that as the proxy</li>
  <li>Set default values for other properties on WebProxy, HttpClient, etc. (removed on the example above because it works fine on .net standard)</li>
  </ol>
  
  <p>I've run out of ideas and things to try. I have the following questions:</p>
  
  <ol>
  <li>Does the code need to be different between .net core vs .net framework</li>
  <li>Are there additional things that need to go into appsettings.json (ie. the config that would have gone into web.config)</li>
  <li>Is there any additional configuration code required in Startup.cs</li>
  <li>Should I be looking to use an external library</li>
  <li>How would I trouble shoot what the issue is? Fiddler doesn't seem to be helping but then I haven't looked to hard at configuring it.</li>
  </ol>