C#对https api的第一次调用非常慢,但python还可以
在我的C#dotnet桌面应用程序中,我使用restclient lib调用我的https API,用户登录后的第一次调用总是需要10秒以上!我尝试了谷歌能找到的一切:C#对https api的第一次调用非常慢,但python还可以,c#,https,C#,Https,在我的C#dotnet桌面应用程序中,我使用restclient lib调用我的https API,用户登录后的第一次调用总是需要10秒以上!我尝试了谷歌能找到的一切: try { // Equal to: ipconfig /flushdns bool res = Win32API.DnsFlushResolverCache(); _log.InfoFormat("DnsFlushResolverCache returns {0}", res); }
try
{
// Equal to: ipconfig /flushdns
bool res = Win32API.DnsFlushResolverCache();
_log.InfoFormat("DnsFlushResolverCache returns {0}", res);
}
finally
{
//nothing to do.
}
System.Net.WebRequest.DefaultWebProxy = null;
System.Net.HttpWebRequest.DefaultWebProxy = null;
System.Net.ServicePointManager.Expect100Continue = false;
client = new RestClient(endpoint);
client.Proxy = null;
client.BaseHost = server_host;
client.AddDefaultHeaders(headers);
// ignore certificate trust
client.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
client.Timeout = _restClientTimeout;
... //url is https://192.168.1.1/api/xxx
DateTime beginat = DateTime.Now;
IRestResponse response = client.Execute(request);
TimeSpan span = DateTime.Now.Subtract(beginat);
_log.InfoFormat("timespan: {0} seconds.", span.TotalSeconds)
HttpClient
是否表现出相同的行为?如果延迟为30秒,则代理设置可能为true。请参阅:我不需要代理。HttpClient
是否表现出相同的行为?如果延迟为30秒,则代理设置可能为true。看:我不需要代理。