6.55HttpClientOptions Extended Configuration (JSON Serialization)
Created on Aug 17, 2026~3 min read
The framework supports customizing options for HttpClient (such as JSON serialization behavior) through the IHttpClientBuilder.ConfigureOptions() extension method, and provides an overload that supports injectable service resolution. The example is as follows:
// Configure the default clientservices.AddHttpClient(string.Empty) .ConfigureOptions(options => // or use the overload: .ConfigureOptions((options, serviceProvider) => { options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; });// Configure a specific clientservices.AddHttpClient("github") .ConfigureOptions(options => // or use the overload: .ConfigureOptions((options, serviceProvider) => { options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; });With this configuration, you can customize the JSON serialization behavior for different HTTP client instances to meet the needs of specific remote requests.
HttpClientOptions contains the following properties:
- Properties:
JsonSerializerOptions:JSONserialization configuration (of typeJsonSerializerOptions).JsonResponseWrapper: Specifies theJSONresponse deserialization wrapper (of typeJsonResponseWrapper?).UseJsonResponseWrapper: Whether to globally enable theJSONresponse deserialization wrapper (of typebool).AccessTokenProvider:Access Tokenprovider configuration (of typeIHttpAccessTokenProvider?).RequestEventHandler:HTTPevent handler provider configuration (of typeIHttpRequestEventHandler?).QuotaLimits: API call quota limit configuration (of typeDictionary<string, HttpQuotaLimit>?).