Skip to content

Instantly share code, notes, and snippets.

@molekilla
Created January 26, 2018 22:06
Show Gist options
  • Save molekilla/debd4d0a058cb33eed24816b0c28fa2b to your computer and use it in GitHub Desktop.
Save molekilla/debd4d0a058cb33eed24816b0c28fa2b to your computer and use it in GitHub Desktop.
Requests a REST API with Basic Authentication
# Call REST API
$SecurePassword = Get-Content httpbin_creds.txt | ConvertTo-SecureString -Key (1..16)
$Username = "johnlopez"
$cred = New-Object System.Management.Automation.PSCredential ($Username, $SecurePassword)
Invoke-RestMethod -Uri "http://httpbin.org/basic-auth/$Username/password123456789" `
-Method Get -Credential $cred -ContentType "application/json" -Body $json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment