Private/GetHttpRequestWithCookie.ps1
$request_timeout_warmup = 60; # Make a get request to a $url while forcing the instance using the ARRAfinity cookie with $instanceGuid function GetHttpRequestWithCookie( [Parameter(Mandatory=$True)] [string]$defaultHostName, [Parameter(Mandatory=$True)] [string]$url, [Parameter(Mandatory=$False)] [string]$instanceGuid, [Parameter(Mandatory=$False)] [string]$requestTimeoutWarmup) { if ($requestTimeoutWarmup -eq $null) { $requestTimeoutWarmup = $request_timeout_warmup } $session = New-Object Microsoft.PowerShell.Commands.WebRequestSession; if (![string]::IsNullOrEmpty($instanceGuid)){ $cookie = New-Object System.Net.Cookie; # To force the instance you can set a cookie named ARRAffinity, this is what Azure uses to assign an Instance by ID # The domain name has to be the domain of the url calling the instance preceded with a '.' $cookie.Name = "ARRAffinity"; $cookie.Value = $instanceGuid; $cookie.Domain = ".$defaultHostName"; $session.Cookies.Add($cookie); } $httpResponse = Invoke-WebRequest -Uri $url -WebSession $session -TimeoutSec $requestTimeoutWarmup; return $httpResponse; } |