[英]powershell Accepting self-signed certificates using ServerCertificateValidationCallback
I cannot seem to get this to work using Powershell 5.1. 我似乎无法使用Powershell 5.1使它正常工作。 The device is a Cisco MX800 CE9.3. 设备是Cisco MX800 CE9.3。
$url = "https://10.1.135.20/getxml?location=/Status"
[Net.ServicePointManager]::ServerCertificateValidationCallback={$true}
$webclient = New-Object System.Net.Webclient
$credCache = New-Object System.Net.CredentialCache
$creds = New-Object System.Net.NetworkCredential($user,$pwd)
$credCache.Add($url, "Basic", $creds)
$webclient.Credentials = $credCache
$webpage = $webclient.DownloadString($url)
Running this script using http returns XML as expected, but using https returns the error below 使用http运行此脚本将按预期返回XML,但使用https将返回以下错误
Exception calling "DownloadString" with "1" argument(s): "The underlying connection was closed: An unexpected error occurred on a send." “使用” 1“参数调用” DownloadString“的异常:”基础连接已关闭:发送时发生意外错误。“ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException + CategoryInfo:未指定:(:) [],MethodInvocationException + FullyQualifiedErrorId:WebException
In the case above, after searching for answers, I dug in and did packet captures. 在上述情况下,在寻找答案之后,我挖了一下并进行了数据包捕获。 One packet capture with powershell talking to the server and one packet capture with a web browser talking to the server. 使用Powershell与服务器对话时捕获一个数据包,通过Web浏览器与服务器对话时捕获一个数据包。
The PS Client Hello was using TLS1.0 PS Client Hello使用的是TLS1.0
The Web browsers Client Hello was using TLS1.2 Web浏览器Client Hello使用的是TLS1.2
So, in PS I added this to the code and I was able to use https against the server. 因此,在PS中,我将其添加到了代码中,从而能够对服务器使用https。 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 [Net.ServicePointManager] :: SecurityProtocol = [Net.SecurityProtocolType] :: Tls12
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.