How do I use invoke-webrequest with basic authentication header in PowerShell? or What's the correct

14 Replies, 1095 Views

Hey! I had the same issue last week. Turns out, some APIs are picky about trailing slashes in the URL. Try removing or adding one to your URI.

Also, double-check if the API expects the auth header in a different format. Sometimes it's "Bearer" instead of "Basic."

For a cleaner way, you could use `-Credential` with `Get-Credential` instead of manually encoding:
```powershell
$cred = Get-Credential
Invoke-WebRequest -Uri "https://example.com" -Credential $cred
```
Might save you some headaches!

Messages In This Thread



Users browsing this thread: 1 Guest(s)