Powershell - Invoke-WebRequest - 下载问题

问题描述 投票:0回答:0

我在尝试使用 powershell 下载两个文件时遇到了一个大问题。 已经尝试了很多,我遇到了重定向问题、超时问题等。 我希望有人对为什么这个简单的脚本根本不起作用有所了解。 提前致谢。

$currDate = (Get-Date -UFormat %Y).ToString(), (Get-Date -UFormat %m).ToString()
$outPath = "M:\INDICES"
$files = @(
            @{
                Uri =     "https://www.caixa.gov.br/Downloads/FGTS-SEFIP-GRF-%C3%8Dndices-Recolhimento-INSS-em-Atraso-SE/SE$($currDate[0])$($currDate[1]).zip"
                OutFile = "$outPath\SE$($currDate[0])$($currDate[1]).zip"
            },
            @{
                Uri = "https://www.caixa.gov.br/Downloads/FGTS-SEFIP-GRF-Tabela-Coeficientes-FGTS-em-Atraso-TF/TF$($currDate[0])$($currDate[1]).zip"
                OutFile = "$outPath\TF$($currDate[0])$($currDate[1]).zip"
            }
         )

foreach ($file in $files) {
    #I tried Invoke-WebRequest with -UseBasicParsing, $userAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome and -DisableKeepAlive, none worked.
    Invoke-WebRequest -Uri $file.Uri -OutFile $file.OutFile
    #I tried Start-BitsTransfer too, but hangs... Sometimes I get too many redirections error. I tried async too.
    #Start-BitsTransfer -Source $file.Uri -Destination $file.OutFile
    #I tried (New-Object System.Net.WebClient).DownloadFile, Create file with 0 bytes and I get timeout.
    #(New-Object System.Net.WebClient).DownloadFile($file.Uri, $file.OutFile)
}
powershell invoke-webrequest
© www.soinside.com 2019 - 2024. All rights reserved.