所以当我运行这个脚本时
powershell (New-Object System.Net.WebClient).DownloadFile('https://www.somewebsite.com', 'Somefolder\Somefile.zip')
我收到错误
Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request."
At line:1 char:5
+ & { (New-Object Net.WebClient).DownloadFile('https://www.dropbox.com/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
答案1
由于行业对网络的改变,您现在必须使用 TLS 来连接网站。
# Required for use with web SSL sites
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
查看具体信息:
https://docs.microsoft.com/en-us/powershell/module/tls/?view=windowsserver2022-ps https://devblogs.microsoft.com/powershell/powershell-gallery-tls-support https://www.powershellgallery.com/packages/Test-TlsProtocols/1.0.0
如果您希望将它们全部包含在您的代码中,那么就是这样:
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols