曲棍球上传错误:Invoke-RestMethod:底层连接已关闭:无法建立

时间:2017-08-18 06:41:30

标签: rest powershell proxy hockeyapp

我正在尝试使用PowerShell脚本将appx上传到曲棍球应用。 当我运行PowerShell脚本时出现以下错误:

Invoke-RestMethod : The underlying connection was closed: Could not establish 
  trust relationship for the SSL/TLS secure channel.

  At C:\PROG\WorkWise-Windows\UploadToHokeyScript\HockeyApp_HPWorkWiseTrayUploadS
  cript.ps1:20 char:13
  + $response = Invoke-RestMethod -Method POST -Uri $create_url -Header @ ...
  +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:Htt 
     pWebRequest) [Invoke-RestMethod], WebException
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe 
     ll.Commands.InvokeRestMethodCommand

非常感谢帮助。

1 个答案:

答案 0 :(得分:0)

在Invoke-restMethod -Uri

之上添加以下步骤
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
    public bool CheckValidationResult(
        ServicePoint srvPoint, X509Certificate certificate,
        WebRequest request, int certificateProblem) {
        return true;
    }
}
"@

[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy 
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12