Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-RestMethod : The remote server returned an error: (401) Unauthorized #3

Open
kwab opened this issue Feb 17, 2023 · 0 comments
Open

Comments

@kwab
Copy link

kwab commented Feb 17, 2023

OS: Windows Server 2012
PowerShell: v5
DDNS service: Google
Cause: Powershell does not pass the password correctly.
Solution: Encode the user credentials in Base64 and add to request headers.

$authInfo = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$username`:$password"))
$headers = @{"X-Requested-With"="$userAgent";"Authorization"="Basic $authInfo"}
$result = Invoke-Restmethod -Method GET -Uri $uri -headers $headers

Credit: https://success.qualys.com/support/s/article/000003066#:~:text=401%20Unauthorized%20means%20that%20the,added%20to%20the%20request%20headers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant