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

14 Replies, 1168 Views

"Having trouble with invoke-webrequest with basic authentication header—any tips?"

Hey folks,

So I'm trying to use invoke-webrequest with basic authentication header, but it's being a pain. I keep getting 401 errors, and I *know* my creds are right.

I’ve tried stuff like:
```powershell
$headers = @{ Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("user:pass")) }
Invoke-WebRequest -Uri "https://example.com" -Headers $headers
```
But no luck. Am I missing something obvious?

Also, is there a cleaner way to do this? Feels like I’m overcomplicating it.

Thanks in advance!

(PS: If you’ve got a step-by-step breakdown, even better. My brain’s fried.)

Messages In This Thread
How do I use invoke-webrequest with basic authentication header in PowerShell? or What's the correct - by - 20-01-2025, 04:16 PM



Users browsing this thread: 1 Guest(s)