gpt4 book ai didi

.net - 使用 Powershell 中的异步 API 进行运行空间问题

转载 作者:行者123 更新时间:2023-12-02 23:12:51 27 4
gpt4 key购买 nike

我正在 Powershell 中调用一个库,该库使用 .NET HttpClient 发出 POST 请求。客户端调用在后台线程上运行。对于 HTTP 来说它工作得很好。然而,当我使用 HTTPS 时,我遇到了问题。服务器未使用有效的签名证书。我使用以下方法正确禁用了该检查:

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

仅会遇到与运行空间相关的错误:

System.Management.Automation.PSInvalidOperationException: There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: $true

根据一些研究,这似乎与 API 是异步/使用任务这一事实有关。

任何帮助将不胜感激。

最佳答案

尝试改用证书策略?

add-type @" 
using System.Net;
using System.Security.Cryptography.X509Certificates;

public class NoSSLCheckPolicy : ICertificatePolicy {
public NoSSLCheckPolicy() {}
public bool CheckValidationResult(
ServicePoint sPoint, X509Certificate cert,
WebRequest wRequest, int certProb) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = new-object NoSSLCheckPolicy

关于.net - 使用 Powershell 中的异步 API 进行运行空间问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31360980/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com