Skip to content

Instantly share code, notes, and snippets.

@yujp
Last active April 20, 2021 15:07
Show Gist options
  • Save yujp/b184be7f364f2a67e7ec687655df32d8 to your computer and use it in GitHub Desktop.
Save yujp/b184be7f364f2a67e7ec687655df32d8 to your computer and use it in GitHub Desktop.
Add-Type -AssemblyName System.Net.Http
# proxy
$bypassOnLocal = $TRUE
$proxy = [System.Net.WebRequest]::GetSystemWebProxy()
#$proxy = New-Object System.Net.WebProxy("http://localhost:8888", $bypassOnLocal)
#$proxy.Credentials = [System.Net.CredentialCache].DefaultNetworkCredentials
#$proxy.Credentials = New-Object System.Net.NetworkCredential("username", "password")
$password = ConvertTo-SecureString "password" -asplaintext -force
$cred = New-Object System.Management.Automation.PsCredential "username",$password
#$proxy.Credentials = $cred
#[System.Net.WebRequest]::DefaultWebProxy = $proxy
# show the proxy URL
$proxy.GetProxy('https://google.com') | Select -ExpandProperty OriginalString
$h = New-Object System.Net.Http.HttpClientHandler
$h.UseProxy = $TRUE
$h.Proxy = $proxy
#$h.Credentials =
$h.PreAuthenticate = $TRUE
$h.UseDefaultCredentials = $TRUE
$h.UseCookies = $TRUE
#$h.DefaultProxyCredentials =
$url = "https://www.google.com/"
(New-Object System.Net.Http.HttpClient($h)).GetAsync($url)
(New-Object System.Net.Http.HttpClient).GetAsync($url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment