0

I am trying to use an invoke-webrequest or invoke-RestMethod for a curl command but can't quite get it right. The curl command that functions is: curl.exe -X GET -H "Content-Type: application/json" --user 'blahblah:blahblah' https://ourdomain.learnupon.com/api/v1/users

I have attempted: $headers = @{ '--user' = 'blahblah:blahblah' } Invoke-RestMethod -Method Post -Uri 'https://ourdomain.learnupon.com/api/v1/users' -ContentType "application/json" -Headers $headers

and also: $post_values = @{'--user'='blahblah:blahblah'} Invoke-WebRequest -Uri https://ourdomain.learnupon.com/api/v1/users -Method POST -Body $post_value

Any help would be super appreciated!

TankCR
  • 61
  • 1
  • 7
  • The ```--user``` parameter is specific to curl - it adds an ```Authorization``` header to the HTTP request (see see https://stackoverflow.com/a/62968667/3156906). The equivalent for PowerShell would be ```-Headers @{ "Authorization" = "Basic xxxxxx" }``` (replace ```xxxxxx``` with the appropriate base64 string for your username/pasword combo). – mclayton Feb 02 '22 at 22:56
  • Does this answer your question? [PowerShell's Invoke-RestMethod equivalent of curl -u (Basic Authentication)](https://stackoverflow.com/questions/24672760/powershells-invoke-restmethod-equivalent-of-curl-u-basic-authentication) – zett42 Feb 02 '22 at 23:00

0 Answers0