The following code in a webapi application targetting netcoreapp2.0 results in "One or more errors occurred. (The remote server returned an error: (401) Unauthorized.)'":
var url = "..."; var webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.UseDefaultCredentials = true; webRequest.CookieContainer = new CookieContainer(); webRequest.Method = "GET"; using (var response = webRequest.GetResponseAsync().Result) { ......
I also get a 401 with WebClient. However, I don't run into an authentication problem when the app is targetting net471.
I'm trying to pass along Windows credentials along in this request. Why does this work only if I target vanilla .NET? Is there a workaround?