获取"无法找到类型[System.Net.ServicePointManager]。"在PowerShell for OS X中

时间:2017-05-05 16:49:25

标签: macos powershell powershell-core

我尝试调试使用 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

要复制此问题:

1 个答案:

答案 0 :(得分:0)

在直到版本5的Windows PowerShell上,由于Invoke-WebRequest cmdlet没有方便的方法来忽略证书检查,因此您需要尝试使用的解决方法。

在PowerShell 6+中,由于开放源代码世界中普遍使用自签名证书,因此Invoke-WebRequest已升级为包括许多新的开关参数来处理它们。特别要看一下documentation for the cmdlet中的-SkipCertificateCheck参数。

该参数将允许您在尝试执行此操作时接受未知证书来加密连接。