HttpClient超时时间
- 建立连接超时时间
var httpClient = new HttpClient(new SocketsHttpHandler() { ConnectTimeout = ... });
- 响应超时时间
httpClient.TimeOut = ....
services.AddHttpClient("SSR", httpClient =>
{
//响应超时时间
httpClient.Timeout = new System.TimeSpan(0, 0, 15);
})
.ConfigurePrimaryHttpMessageHandler(() =>
{
return new SocketsHttpHandler()
{
//连接超时时间
ConnectTimeout = new System.TimeSpan(0, 0, 2),
//忽略证书校验
SslOptions = new System.Net.Security.SslClientAuthenticationOptions
{
RemoteCertificateValidationCallback = (_, _, _, _) => true
}
};
});
https://docs.microsoft.com/en-us/dotnet/api/system.net.http.socketshttphandler.connecttimeout?view=net-6.0
https://github.com/dotnet/runtime/issues/11594