6.16HttpRemoteOptions Configuration Options
Created on Aug 17, 2026~1 min read
When adding the HTTP remote request service using the services.AddHttpRemote() method, an IHttpRemoteBuilder instance is returned. Through this instance, you can access and configure HttpRemoteOptions, which include properties such as the default request content type and JSON serialization settings:
services.AddHttpRemote(builder => {}) .ConfigureOptions(options => { // Configure the default request content type options.DefaultContentType = "text/plain"; // "application/json" is recommended // Set the default save directory for file downloads options.DefaultFileDownloadDirectory = @"C:\Workspaces\"; // Set the request profiler log level, Warning by default options.ProfilerLogLevel = LogLevel.Warning; // Set whether requests should follow redirect responses, true by default options.AllowAutoRedirect = true; // Set the maximum number of redirects a request follows, 50 by default options.MaximumAutomaticRedirections = 50; // Set the fallback request base address, effective when HttpClient's BaseAddress is not configured and the request address is a relative address options.FallbackBaseAddress = new Uri("https://localhost:5000"); // Customize JSON serialization options options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; // Set the provider source used to replace configured template parameters in URL addresses options.Configuration = builder.Configuration; // If using the Furion framework, you can directly set App.Configuration // Set the URL parameter formatter options.UrlParameterFormatter = new UrlParameterFormatter(); // The fallback log output delegate when the logging service or console output is unavailable options.FallbackLogger = Console.WriteLine; // Can be replaced with Debug.WriteLine // Set the unified HttpRequestBuilder configurator options.RequestBuilderConfigurator = null; // null by default });The ConfigureOptions method allows more customized configuration of the HTTP remote request service, such as adjusting JSON serialization behavior. In addition, ConfigureOptions also provides an overload that supports service resolution. An example is shown below:
services.AddHttpRemote(builder => {}) .ConfigureOptions((options, serviceProvider) => { // Resolve the required service var yourService = serviceProvider.GetRequiredService<IYourService>(); // Other configuration code });