[英]HttpClientHandler UseDefaultCredentials in .NET Core
With the following running in a .NET Framework 4.7.2 Console application and some_url
pointing to a server in my Windows network that uses Kerberos, I get a HTTP code of 200 back:通过在.NET Framework 4.7.2控制台应用程序中运行以下内容,并且some_url
指向我的 Windows 网络中使用 Kerberos 的服务器,我得到了200的 HTTP 代码:
var handler = new HttpClientHandler { UseDefaultCredentials = true };
var client = new HttpClient(handler);
var code = client.GetAsync(some_url).Result.StatusCode
but using the same code in a .NET Core 3.1 application gives a 401 instead.但是在.NET Core 3.1应用程序中使用相同的代码会产生401 。 This is the same as I get when running in .NET Framework 4.7.2 but not setting UseDefaultCredentials
to true
, leading me to believe the .NET Core 3.1 version does not pass the credentials along.这与我在.NET Framework 4.7.2 中运行但未将UseDefaultCredentials
设置为true
时得到的结果相同,这让我相信.NET Core 3.1版本不会传递凭据。
What do I need to do to get a .NET Core 3.1 application to pass the current credentials?我需要做什么才能让.NET Core 3.1应用程序传递当前凭据? I've tried playing around with setting the Credentials
on the handler
to an instance of NetworkCredential
but to no avail.我试过将handler
上的Credentials
设置为NetworkCredential
的实例,但无济于事。
you should change AllowAutoRedirect to false and loop over the response message您应该将 AllowAutoRedirect 更改为 false 并遍历响应消息
HttpResponseMessage httpResponse;
do
{
httpResponse = await httpClient.GetAsync(uri);
if (httpResponse.Headers.Contains("Location"))
{
//Find the redirection address
uri = httpResponse.Headers.Location.OriginalString;
}
else
{
throw new ApplicationException("No Location header found in web response");
}
} while (httpResponse.StatusCode == HttpStatusCode.Redirect);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.