Skip to content

Commit

Permalink
fix header usage during request
Browse files Browse the repository at this point in the history
  • Loading branch information
majkinetor authored Sep 11, 2018
1 parent b976947 commit e8e9a29
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions AU/Private/request.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ function request( [string]$Url, [int]$Timeout, $Options ) {
if ([string]::IsNullOrWhiteSpace($url)) {throw 'The URL is empty'}
$request = [System.Net.WebRequest]::Create($Url)
if ($Timeout) { $request.Timeout = $Timeout*1000 }
if ($Options.Headers) { $Options.Headers.Keys | %{ $request.Headers.add($_, $Options.Headers[$_]) } }


$Options.Headers.Keys | % {
if ([System.Net.WebHeaderCollection]::IsRestricted($_)) {
$key = $_.Replace('-','')
$request.$key = $Options.Headers[$_]
}
else {
$request.Headers.add($_, $Options.Headers[$_])
}
}

$response = $request.GetResponse()
$response.Close()
$response
Expand Down

0 comments on commit e8e9a29

Please sign in to comment.