add defensive logic
This commit is contained in:
parent
08daca848b
commit
e3233fd19f
|
@ -201,10 +201,13 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
|
||||
// set the cookies to allow HttpClient API calls to be authenticated
|
||||
var httpContextAccessor = s.GetRequiredService<IHttpContextAccessor>();
|
||||
if (httpContextAccessor.HttpContext != null)
|
||||
{
|
||||
foreach (var cookie in httpContextAccessor.HttpContext.Request.Cookies)
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("Cookie", cookie.Key + "=" + cookie.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return client;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user