Forum Discussion
jonnt111325
Jul 25, 2021Copper Contributor
Proxy Authentication
Hi, I am trying to create a PowerShell script to get my proxy ip from ipify.org and save it to a file I have used their sample code but get the error, 407 Proxy Authentication Required ...
gastone
Jul 26, 2021Brass Contributor
from https://stackoverflow.com/questions/20471486/how-can-i-make-invoke-restmethod-use-the-default-web-proxy
$headers = @{"X-My-ApiKey"=$apiKey}
$contentType = "application/json"
$proxyUri = [Uri]$null
$proxy = [System.Net.WebRequest]::GetSystemWebProxy()
if ($proxy)
{
$proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
$proxyUri = $proxy.GetProxy("$server$url")
}
if ("$proxyUri" -ne "$server$url")
{
Write-Host "Using proxy: $proxyUri"
return Invoke-RestMethod -Uri $server$url -ContentType $contentType -Headers $headers -Method $method -UseDefaultCredentials -Proxy $proxyUri -ProxyUseDefaultCredentials
}
else
{
return Invoke-RestMethod -Uri $server$url -ContentType $contentType -Headers $headers -Method $method -UseDefaultCredentials
}