i have tried using socketsHttpHandler and httpclienthandler to connect to my api which requires a ssl. It was working fine in my local, but once i migrate to server, the first connection will always fail where handshake will take 15 seconds resulting in 408 timeout.

below are example of SocketsHttpHandler
SslClientAuthenticationOptions sslOptions = new SslClientAuthenticationOptions
{
RemoteCertificateValidationCallback = delegate { return true; },
};
using SocketsHttpHandler handler = new SocketsHttpHandler()
{
SslOptions = sslOptions,
ConnectCallback = async (context, cancellationToken) =>
{
IPHostEntry ipHostEntry = await Dns.GetHostEntryAsync(context.DnsEndPoint.Host);
IPAddress ipAddress = ipHostEntry
.AddressList
.FirstOrDefault(i => i.AddressFamily == AddressFamily.InterNetwork);
if (ipAddress == null)
{
throw new Exception($"No IP4 address for {context.DnsEndPoint.Host}");
}
TcpClient tcp = new();
await tcp.ConnectAsync(ipAddress, context.DnsEndPoint.Port, cancellationToken);
return tcp.GetStream();
}
};
using var httpClient = new HttpClient(handler);
using var content = new FormUrlEncodedContent(GetHeaderSessionStart(login, password));
content.Headers.Clear();
content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
HttpResponseMessage response = await httpClient.PostAsync(address, content);
below are example of HttpClientHandler
var handler = new HttpClientHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
handler.ServerCertificateCustomValidationCallback =
(httpRequestMessage, cert, cetChain, policyErrors) =>
{
return true;
};
handler.CheckCertificateRevocationList = false;
using var httpClient = new HttpClient(handler);
i tried increasing timeout for httpclient, but it does not work either