0

I have a very simple curl command, this works for me (not using basic auth- the service just expects the token to be in URL):

curl -v -X POST https://Dkdjhf928hfDJFSDFJSK@sonarcloud.io/api/projects/create -d "name=sdfsdfsdf&project=sdfsdfdsf&organization=zzzzz"

This does not work:

Invoke-WebRequest -Method POST `
                  -Body 'name=sdfsdfsdf&project=sdfsdfdsf&organization=zzzzz' `
                  -Uri 'https://Dkdjhf928hfDJFSDFJSK@sonarcloud.io/api/projects/create'

powershell must be mangling something because I get this error:

Invoke-WebRequest : {"errors":[{"msg":"Insufficient privileges"}]}

Is there some default way curl sends body or data that powershell does not?

red888
  • 27,709
  • 55
  • 204
  • 392
  • Possible duplicate of [Use Invoke-WebRequest with a username and password for basic authentication on the GitHub API](https://stackoverflow.com/questions/27951561/use-invoke-webrequest-with-a-username-and-password-for-basic-authentication-on-t) – Ross Presser Jul 24 '19 at 16:34
  • i think its obvious my question is different im not using basic auth or `-u`. the token is included in the url. I want to understand why this is not working with powershell and if it is mangling something or my params are wrong – red888 Jul 24 '19 at 16:49
  • Maybe you need to set `Content-Type` then. -d normally uses [`application/x-www-form-urlencoded`](https://curl.haxx.se/docs/manpage.html#-d). – Ross Presser Aug 23 '19 at 19:59
  • SonarCloud uses HTTP Basic authentication. Your `curl` example is equivalent to `curl -v -u "Dkdjhf928hfDJFSDFJSK:" https://sonarcloud.io/...`. So the linked post looks right on the money! – janos Oct 05 '19 at 19:03

0 Answers0