This library provides extension methods for setting up an HttpClient.
- Configure Basic HttlClient properties, such as SSL Protocols.
- Configure an ITokenClient as the source of the Authorization header.
- Configure the Authorization header with a static Bearer token value.
- Configure any header with a static value.
IServiceCollection services = ...;
services.AddHttpClient("test")
.UseSslProtocols(SslProtocols.Tls12); // Sets the primary HttpClientHandler to use TLS 1.2
IServiceCollection services = ...;
services.AddTokenClient("tokenClient123", ...);
services.AddHttpClient("test")
.AddTokenClient("tokenClient123"); // Adds the header "Authorization: Bearer {access_token}"
IServiceCollection services = ...;
services.AddTokenClient(...);
services.AddHttpClient("test")
.AddTokenClient(svc =>
{
return svc
.GetRequiredService<ITokenClientFactory>()
.GetTokenClient();
}); // Adds the header "Authorization: Bearer {access_token}"
IServiceCollection services = ...;
ITokenClient tokenClient = ...;
services.AddHttpClient("test")
.AddTokenClient(tokenClient); // Adds the header "Authorization: Bearer {access_token}"
IServiceCollection services = ...;
string bearerToken = "REPLACE_ME";
services.AddHttpClient("test")
.AddBearerToken(bearerToken); // Adds the header "Authorization: Bearer REPLACE_ME"
IServiceCollection services = ...;
string scheme = "HDR_SCHEME";
string parameter = "HDR_PARAM";
services.AddHttpClient("test")
.AddAuthorizationHeader(scheme, parameter); // Adds the header "Authorization: HDR_SCHEME HDR_PARAM"
IServiceCollection services = ...;
string name = "HDR_NAME";
string value = "HDR_VALUE";
services.AddHttpClient("test")
.AddHeader(name, value); // Adds the header "HDR_NAME: HDR_VALUE"