【发布时间】:2019-12-10 05:28:40
【问题描述】:
我需要每天从日期已过的网站下载文件。我尝试使用以下代码 -
$url = "https://www.theocc.com/webapps/threshold-securities?reportDate=20190730"
$output = "C:\Users\Himanshu.Vats\Downloads\"
Invoke-WebRequest -Uri $url -OutFile $output
但它给出了错误-
Invoke-WebRequest :底层连接已关闭:发送时发生意外错误。 在行:3 字符:1 + 调用-WebRequest -Uri $url -OutFile $output + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
【问题讨论】:
-
我也试过这个 - $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile("theocc.com/webapps/threshold-securities","C:\Users\Himanshu.Vats\Downloads\") 这给出错误 -
-
请看这篇文章:stackoverflow.com/questions/41618766/…(即在调用
Invoke-WebRequest之前尝试设置[Net.ServicePointManager]::SecurityProtocol = 'Tls11,Tls12')
标签: powershell