fix win_get_url var renames ala xpicio fix PR #2378

reimplements #2378 sans formatting merge conflicts
This commit is contained in:
nitzmahone 2016-01-15 08:56:14 -08:00 committed by Matt Clay
parent 7be08b00b0
commit 821fb6c0ab

View file

@ -55,22 +55,22 @@ if($skip_certificate_validation){
$force = Get-Attr -obj $params -name "force" "yes" | ConvertTo-Bool
If ($force -or -not (Test-Path $dest)) {
$client = New-Object System.Net.WebClient
$webClient = New-Object System.Net.WebClient
if($proxy_url) {
$proxy_server = New-Object System.Net.WebProxy($proxy_url, $true)
if($proxy_username -and $proxy_password){
$proxy_credential = New-Object System.Net.NetworkCredential($proxy_username, $proxy_password)
$proxy_server.Credentials = $proxy_credential
}
$client.Proxy = $proxy_server
$webClient.Proxy = $proxy_server
}
if($username -and $password){
$client.Credentials = New-Object System.Net.NetworkCredential($username, $password)
$webClient.Credentials = New-Object System.Net.NetworkCredential($username, $password)
}
Try {
$client.DownloadFile($url, $dest)
$webClient.DownloadFile($url, $dest)
$result.changed = $true
}
Catch {
@ -89,7 +89,7 @@ Else {
$webRequest.Method = "GET"
[System.Net.HttpWebResponse]$webResponse = $webRequest.GetResponse()
$stream = New-Object System.IO.StreamReader($response.GetResponseStream())
$stream = New-Object System.IO.StreamReader($webResponse.GetResponseStream())
$stream.ReadToEnd() | Set-Content -Path $dest -Force -ErrorAction Stop