Created
September 1, 2016 22:23
-
-
Save mikebranstein/5c147cece94a6ec4b0f055ea713cb554 to your computer and use it in GitHub Desktop.
make an web request using basic authentication in powershel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Invoke-AuthenticatedWebRequest { | |
param ( | |
[string] $uri, | |
[string] $userName, | |
[string] $password, | |
[string] $method, | |
[string] $contentType | |
) | |
$credentials = "$($userName):$($password)" | |
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credentials)) | |
$basicAuthValue = "Basic $encodedCredentials" | |
$headers = @{ | |
Authorization = $basicAuthValue | |
} | |
Invoke-WebRequest -Uri $uri -Headers $headers -Method $method -ContentType $contentType -DisableKeepAlive | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment