我发现当我使用HttpWebRequest建立SSL\TLS连接时,调用时需要近30秒
request.GetRequestStream()
Run Code Online (Sandbox Code Playgroud)
当我启用了跟踪启用堆栈跟踪时,我发现2s会找到poxy,所以我在app.config中禁用了它:
<system.net>
<defaultProxy enabled="false" useDefaultCredentials="false">
<proxy/>
<bypasslist/>
<module/>
</defaultProxy>
</system.net>
Run Code Online (Sandbox Code Playgroud)
下一个接近28s的点是在
at System.Net.Security.SecureChannel.AcquireClientCredentials(Byte[]& thumbPrint)
Run Code Online (Sandbox Code Playgroud)
在检查方法体后,我发现了对X509Chain.Build()的调用,并且花了将近25秒来构建证书链.
有趣的是,当你构造新的HttpWebReqest并再次尝试(没有app重启)时,执行请求需要几个ms.
谁能建议做什么?缓存请求不是一个选项,它应该从app运行快速.
更新:
我在X509Chain.BuildChain()中发现需要30秒的调用,它是:
if (!CAPISafe.CertGetCertificateChain(hChainEngine, pCertContext, ref pTime, invalidHandle, ref cert_chain_para, dwFlags, IntPtr.Zero, ref ppChainContext))
Run Code Online (Sandbox Code Playgroud)
在CAPISafe中声明的方法为:
[DllImport("crypt32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern bool CertGetCertificateChain([In] IntPtr hChainEngine, [In] SafeCertContextHandle pCertContext, [In] ref System.Runtime.InteropServices.ComTypes.FILETIME pTime, [In] SafeCertStoreHandle hAdditionalStore, [In] ref CAPIBase.CERT_CHAIN_PARA pChainPara, [In] uint dwFlags, [In] IntPtr pvReserved, [In, Out] ref SafeCertChainHandle ppChainContext);
Run Code Online (Sandbox Code Playgroud)
所以,它是加密API函数CertGetCertificateChain 还是不知道,下一步做什么...
更新:
我试图禁用CRL和OCSP检查,仍然没有效果:
添加到App.config …