How to use the curl command in PowerShell? How to use the curl command in PowerShell? powershell powershell

How to use the curl command in PowerShell?


Use splatting.

$CurlArgument = '-u', 'xxx@gmail.com:yyyy',                '-X', 'POST',                'https://xxx.bitbucket.org/1.0/repositories/abcd/efg/pull-requests/2229/comments',                '--data', 'content=success'$CURLEXE = 'C:\Program Files\Git\mingw64\bin\curl.exe'& $CURLEXE @CurlArgument


In Powershell 3.0 and above there is both a Invoke-WebRequest and Invoke-RestMethod. Curl is actually an alias of Invoke-WebRequest in PoSH. I think using native Powershell would be much more appropriate than curl, but it's up to you :).

Invoke-WebRequest MSDN docs are here:https://technet.microsoft.com/en-us/library/hh849901.aspx?f=255&MSPPError=-2147217396

Invoke-RestMethod MSDN docs are here:https://technet.microsoft.com/en-us/library/hh849971.aspx?f=255&MSPPError=-2147217396


Or another option you could just call curl.exe using splatting as follows.

> curl.exe '-u', 'xxx@gmail.com:yyyy', '-X', 'POST', 'https://xxx.bitbucket.org/1.0/repositories/abcd/efg/pull-requests/2229/comments',                 '--data', 'content=success'

To know where is curl.exe using this command Get-Command curl.exe

Other option is to delete aliases curl command with Invoke-WebRequest

To see and delete aliaes in PowerShell

>Get-Aliases>Remove-Item alias:curl

Then just runing command without '.exe'

> curl '-u', 'xxx@gmail.com:yyyy', '-X', 'POST', 'https://xxx.bitbucket.org/1.0/repositories/abcd/efg/pull-requests/2229/comments',                 '--data', 'content=success'

I hope this would helps.