feat: use ProxyAddress with Credential when passed to powershell script
In a proxy environment, such as in an enterprise, HTTP(S)_PROXY often takes the form of credentials, i.e., http://user:pass@host:port. When $ProxyAddress is passed in this format, WebProxy does not use the authentication information by default. This PR aims to solve the above problem.
This commit is contained in:
parent
5d1464d5da
commit
d10d64864f
|
@ -416,6 +416,13 @@ function GetHTTPResponse([Uri] $Uri, [bool]$HeaderOnly, [bool]$DisableRedirect,
|
|||
UseDefaultCredentials=$ProxyUseDefaultCredentials;
|
||||
BypassList = $ProxyBypassList;
|
||||
}
|
||||
# If ProxyAddress is contained username and password, then set credentials
|
||||
# e.g. http://(user):(pass)@...
|
||||
if ($ProxyAddress -match '://(.*?):(.*?)@') {
|
||||
$proxyUsername = $matches[1]
|
||||
$proxyPassword = $matches[2]
|
||||
$HttpClientHandler.Proxy.Credentials = New-Object System.Net.NetworkCredential($proxyUsername, $proxyPassword)
|
||||
}
|
||||
}
|
||||
if ($DisableRedirect)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue