powershell下载https文件
Powershell下载https协议文件提示
PS D:\Tools> Invoke-WebRequest "https://github.com/exceptionless/Exceptionless.UI/releases/download/v2.7.1/Exceptionless.UI.2.7.1163.zip" Invoke-WebRequest : 请求被中止: 未能创建 SSL/TLS 安全通道。 At line:1 char:1 + Invoke-WebRequest "https://github.com/exceptionless/Exceptionless.UI/ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand PS D:\Tools>
解决方法
- 方式一
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; Invoke-WebRequest "https://github.com/exceptionless/Exceptionless.UI/releases/download/v2.7.1/Exceptionless.UI.2.7.1163.zip" -OutFile "Exceptionless.UI.2.7.1163.zip"
- 方式二
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 $result = Invoke-WebRequest -Uri "https://github.com/exceptionless/Exceptionless.UI/releases/download/v2.7.1/Exceptionless.UI.2.7.1163.zip" -OutFile "Exceptionless.UI.2.7.1163-2.zip"
- 方式三
Import-Module BitsTransfer $url = "https://dldir1.qq.com/qqfile/qq/QQ9.0.5/23816/QQ9.0.5.exe" Start-BitsTransfer $url D:\Tools\QQ9.0.5.exe #Invoke-Item D:\Tools\QQ9.0.5.exe #下载完成后打开程序
方式三不支持https的Tls12模式,无法下载github的https文件,不推荐使用。