HttpClient超时时间

  1. 建立连接超时时间
var httpClient = new HttpClient(new SocketsHttpHandler() { ConnectTimeout = ... });
  1. 响应超时时间
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

posted @   ChasingDreams  阅读(184)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
点击右上角即可分享
微信分享提示