Sangat gila bahwa OS server yang dirancang untuk menggerakkan beban kerja cloud tidak memiliki metode nyaman yang dibangun untuk permintaan REST / Web sederhana: O
Bagaimanapun, Anda dapat mencoba skrip powershell ini wget.ps1 yang merupakan modifikasi dari Microsoft. Copy-paste di sini untuk kenyamanan
<#
.SYNOPSIS
Downloads a file
.DESCRIPTION
Downloads a file
.PARAMETER Url
URL to file/resource to download
.PARAMETER Filename
file to save it as locally
.EXAMPLE
C:\PS> .\wget.ps1 https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
#>
Param(
[Parameter(Position=0,mandatory=$true)]
[string]$Url,
[string]$Filename = ''
)
# Get filename
if (!$Filename) {
$Filename = [System.IO.Path]::GetFileName($Url)
}
Write-Host "Download: $Url to $Filename"
# Make absolute local path
if (![System.IO.Path]::IsPathRooted($Filename)) {
$FilePath = Join-Path (Get-Item -Path ".\" -Verbose).FullName $Filename
}
if (($Url -as [System.URI]).AbsoluteURI -ne $null)
{
# Download the bits
$handler = New-Object System.Net.Http.HttpClientHandler
$client = New-Object System.Net.Http.HttpClient($handler)
$client.Timeout = New-Object System.TimeSpan(0, 30, 0)
$cancelTokenSource = [System.Threading.CancellationTokenSource]::new()
$responseMsg = $client.GetAsync([System.Uri]::new($Url), $cancelTokenSource.Token)
$responseMsg.Wait()
if (!$responseMsg.IsCanceled)
{
$response = $responseMsg.Result
if ($response.IsSuccessStatusCode)
{
$downloadedFileStream = [System.IO.FileStream]::new($FilePath, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write)
$copyStreamOp = $response.Content.CopyToAsync($downloadedFileStream)
# TODO: Progress bar? Total size?
Write-Host "Downloading ..."
$copyStreamOp.Wait()
$downloadedFileStream.Close()
if ($copyStreamOp.Exception -ne $null)
{
throw $copyStreamOp.Exception
}
}
}
}
else
{
throw "Cannot download from $Url"
}