teamcity运行powershell脚本时,该脚本将使用下一个证书设置(通过此链接Powershell v3 Invoke-WebRequest HTTPS error调用soap服务):
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
当它由teamcity首次运行时,它失败并显示错误:
"The request was aborted: Could not create SSL/TLS secure channel." ---> System.Net.WebException: The
request was aborted: Could not create SSL/TLS secure channel.
at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at CallSite.Target(Closure , CallSite , Object , network )
但是当我在teamcity之后手动运行脚本时,它运行良好。 我很困惑为什么会发生这种情况。