How to use the curl command in PowerShell?

Am using the curl command in PowerShell to post the comment in bit-bucket pull request page through a Jenkins job. I used the below PowerShell command to execute the curl command, but am getting the error mentioned below. Could anyone please help me on this to get it worked?

$CurlArgument="-u :yyyy -X POST --data content=success" $CURLEXE='C:\Program Files\Git\mingw64\bin\curl.exe' & $CURLEXE $CurlArgument 

Error Details:

curl.exe : curl: no URL specified! At line:3 char:1 + & $CURLEXE $CurlArgument + ~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (curl: no URL specified!:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError curl: try 'curl --help' or 'curl --manual' for more information
2

4 Answers

Use splatting.

$CurlArgument = '-u', ':yyyy', '-X', 'POST', ' '--data', 'content=success' $CURLEXE = 'C:\Program Files\Git\mingw64\bin\curl.exe' & $CURLEXE @CurlArgument 
4

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:

Invoke-RestMethod MSDN docs are here:

2

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

> curl.exe '-u', ':yyyy', '-X', 'POST', ' '--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', ':yyyy', '-X', 'POST', ' '--data', 'content=success' 

I hope this would helps.

Instead of curl you can use this command:

(New-Object System.Net.WebClient).DownloadString("") 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like