Created
November 22, 2017 15:59
-
-
Save itsthedoc/a0b5336bad2046a2320606635d4d92f4 to your computer and use it in GitHub Desktop.
Powershell example script to create headers to submit an HTTP request with basic auth
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
$user = "USERNAME" | |
$pass = "PASSWORD" | |
$pair = "${user}:${pass}" | |
#Encode the string to the RFC2045-MIME variant of Base64, except not limited to 76 char/line. | |
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair) | |
$base64 = [System.Convert]::ToBase64String($bytes) | |
#Create the Auth value as the method, a space, and then the encoded pair Method Base64String | |
$basicAuthValue = "Basic $base64" | |
#Create the header Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== | |
$headers = @{ Authorization = $basicAuthValue } | |
#Invoke the web-request | |
Invoke-WebRequest -uri $uri -Headers $headers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment