问题标签 [certificatepolicy]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
54 浏览

.net - PowerShell - 尝试在没有自签名证书问题的情况下进行 REST 调用的添加类型问题

在遇到尝试进行 REST API 调用并避免自签名证书问题后,我试图更好地理解 PowerShell 中的 Add-Type。代码如下。

当我运行它时,它会因错误而中断。

“新对象:找不到类型 [TrustAllCertsPolicy]:验证是否已加载包含此类型的程序集。” 然后,因为失败了,我得到了错误,“Invoke-RestMethod:远程证书无效,因为证书链中的错误:PartialChain”

只是偶然发现它在 PowerShell 5.1.22000.282 中按预期工作而在 PowerShell 7.2.1 中没有。我可以进行哪些更改以使其在两个版本的 PowerShell 中都能正常工作?

更新:这个链接有一些代码可以让它在两个版本的 PowerShell 中运行。我接受了我所做的答案,因为它是最有帮助的,并且因为我正在分享另一个答案。 https://github.com/PowerShell/PowerShell/issues/7092