我尝试调试使用 Invoke-WebRequest 进行https调用的脚本。由于证书错误导致请求不允许,我需要运行以下命令来禁用SSL验证:
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
但是,当我尝试运行此命令时,出现以下错误:
Unable to find type [System.Net.ServicePointManager].
At line:1 char:1
+ [System.Net.ServicePointManager]::ServerCertificateValidationCallback ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.ServicePointManager:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
操作系统:macOS Sierra
要复制此问题:
安装.pkg
Type' powershell'在终端
尝试运行上面的命令。
答案 0 :(得分:0)
在直到版本5的Windows PowerShell上,由于Invoke-WebRequest cmdlet没有方便的方法来忽略证书检查,因此您需要尝试使用的解决方法。
在PowerShell 6+中,由于开放源代码世界中普遍使用自签名证书,因此Invoke-WebRequest已升级为包括许多新的开关参数来处理它们。特别要看一下documentation for the cmdlet中的-SkipCertificateCheck
参数。
该参数将允许您在尝试执行此操作时接受未知证书来加密连接。