Powershell使用基本身份验证下载文件

Powershell使用基本身份验证下载文件,powershell,Powershell,我正在尝试使用PowerShell从我的JFrog repo下载一个文件,但无法使其正常工作 这就是我得到的错误: Exception calling "DownloadFile" with "2" argument(s): "The underlying connection was closed: An unexpected error occurred on a send." At C:\Users\jelte\Documents\myproject\downloadExecuta

我正在尝试使用PowerShell从我的JFrog repo下载一个文件,但无法使其正常工作

这就是我得到的错误:

Exception calling "DownloadFile" with "2" argument(s): "The underlying connection was closed: An unexpected error occurred on a send." At C:\Users\jelte\Documents\myproject\downloadExecutables1.ps1:16 char:1 + $req.DownloadFile('https://myrepo.jfrog.io/myproject/libs-release-loca ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException 我尝试过的事情:

  • 从非安全服务器下载文件,这是可行的。我怀疑基本身份验证出现了问题
  • 我已经检查了用户名和密码是否已填写,我还检查了base64哈希是否正确
  • 将PowerShell置于跟踪模式,这样我就可以获得更清晰的错误,但运气不好。(为什么这些错误如此不清楚?)
  • 使用
    Invoke Webrequest
    ,这可以工作,但速度非常慢
  • 使用cURL来检查它是否是其他东西,这同样有效

  • 尝试将这些行添加到脚本的开头

    $AllProtocols = [System.Net.SecurityProtocolType]'Tls12'
    [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols 
    

    我也经历过类似的情况,但没有一条信息非常丰富的错误消息,问题显然只是我需要将powershell使用的安全协议设置为Tls 1.2。

    您使用的代码正是我下载具有授权的文件所需的代码。谢谢
    $AllProtocols = [System.Net.SecurityProtocolType]'Tls12'
    [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols