6.50Common Property Configuration
Created on Aug 17, 2026~1 min read
// Enable for the default clientservices.AddHttpClient(string.Empty, client =>{ // Configure the base address client.BaseAddress = new Uri("http://localhost:5000"); // Configure the timeout client.Timeout = TimeSpan.FromMinutes(10); // Configure the maximum buffer size for response content client.MaxResponseContentBufferSize = 5 * 1024; // Configure the default HTTP version client.DefaultRequestVersion = HttpVersion.Version10; // Configure default request headers, such as "User-Agent" client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0"); // Configure the version policy used by default when establishing an HTTP connection client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher;});// Enable for a specific clientservices.AddHttpClient("weixin", client =>{ // Configure HttpClient properties});