"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.)
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.)
