Skip to content

Commit b731d3b

Browse files
authored
Update SandboxTest.ps1 to use HttpClient instead of WebClient (#240691)
1 parent af48092 commit b731d3b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Tools/SandboxTest.ps1

+6-5
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ $script:HostGeoID = (Get-WinHomeLocation).GeoID
8989

9090
# Misc
9191
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
92-
$script:WebClient = New-Object System.Net.WebClient
92+
$script:HttpClient = New-Object System.Net.Http.HttpClient
9393
$script:CleanupPaths = @()
9494

9595
# The experimental features get updated later based on a switch that is set
@@ -114,7 +114,7 @@ function Invoke-CleanExit {
114114
[int] $ExitCode
115115
)
116116
Invoke-FileCleanup -FilePaths $script:CleanupPaths
117-
$script:WebClient.Dispose()
117+
$script:HttpClient.Dispose()
118118
Write-Debug "Exiting ($ExitCode)"
119119
exit $ExitCode
120120
}
@@ -186,7 +186,8 @@ function Get-RemoteContent {
186186
Write-Debug "Remote content will be stored at $($localFile.FullName)"
187187
$script:CleanupPaths += $Raw ? @($localFile.FullName) : @() # Mark the file for cleanup when the script ends if the raw data was requested
188188
try {
189-
$script:WebClient.DownloadFile($URL, $localFile.FullName)
189+
$downloadTask = $script:HttpClient.GetByteArrayAsync($URL)
190+
[System.IO.File]::WriteAllBytes($localfile.FullName, $downloadTask.Result)
190191
}
191192
catch {
192193
# If the download fails, write a zero-byte file anyways
@@ -295,7 +296,7 @@ if (!$SkipManifestValidation -and ![String]::IsNullOrWhiteSpace($Manifest)) {
295296
Invoke-CleanExit -ExitCode 3
296297
}
297298
Write-Information "--> Validating Manifest"
298-
$validateCommandOutput =
299+
$validateCommandOutput =
299300
& {
300301
# Store current output encoding setting
301302
$prevOutEnc = [Console]::OutputEncoding
@@ -306,7 +307,7 @@ if (!$SkipManifestValidation -and ![String]::IsNullOrWhiteSpace($Manifest)) {
306307

307308
# Reset the encoding to the previous values
308309
[Console]::OutputEncoding = $prevOutEnc
309-
}
310+
}
310311
switch ($LASTEXITCODE) {
311312
'-1978335191' {
312313
($validateCommandOutput | Select-Object -Skip 1 -SkipLast 1) | Write-Information # Skip the first line and the empty last line

0 commit comments

Comments
 (0)