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

14 Replies, 1152 Views

Here’s a step-by-step that worked for me:

1. Encode creds like you did, but store them in a var first:
```powershell
$auth = "user:pass"
$encoded = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($auth))
```

2. Then, use `-Headers` *and* `-ContentType "application/json"` (if applicable).

3. Run `$Error[0] | fl -Force` after the error to get deets.

Sometimes the server’s error message hides in there.

Messages In This Thread



Users browsing this thread: 1 Guest(s)