36

If I were to issue the command without the --data "...", it works just fine. I've tried Google and I can't find any answers to this problem. Following the directions located here I'm getting the following errors when I attempt to post data with cURL:

PS C:\Users\David> curl --data "SMethod=0" "http://localhost/terra/modules/scripts/Query.php"
Invoke-WebRequest : A positional parameter cannot be found that accepts argument 'SMethod=0'.
At line:1 char:1
+ curl --data "SMethod=0" "http://localhost/terra/modules/scripts/Query.php"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
kneeki
  • 2,444
  • 4
  • 17
  • 27

4 Answers4

50

Your problem is answered here: Running cURL on 64 bit Windows

You're not running curl you're running something called Invoke-WebRequest, which is aliased to curl. You need to unalias curl, download and install curl (if you haven't already).

Community
  • 1
  • 1
Phill Treddenick
  • 1,340
  • 13
  • 18
37

Remove-item alias:curl

this will be happen to curl easily!!

TRY AND FUN.. AND ALSO curl can make your own SHORTEN URL , so Don't need to work with 3rd parties.. :D

sounish nath
  • 567
  • 4
  • 3
9

Use the Command Prompt instead of using PowerShell.

If you are using PowerShell then you will need to prefix the curl command with cmd /c. For example:

cmd /c curl --data "SMethod=0" "http://localhost/terra/modules/scripts/Query.php"
James
  • 3,051
  • 3
  • 29
  • 41
rodster
  • 111
  • 1
  • 6
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 20 '22 at 00:38
  • he means use cmd as opposed to PS – Rob Sedgwick Mar 27 '22 at 17:51
0

As the other answers already mentioned the curl command in powershell is aliased and uses the Invoke-WebRequest cmdlet under the hood. It has similar capabilities to curl.

You can make a POST request and send & receive data without the need to install anything:

curl -body "SMethod=0" "http://localhost/terra/modules/scripts/Query.php" -Method 'POST'

The option -body (Invoke-WebRequest) is the equivalent of -d or --data (curl). The HTTP Method also must be specified.

This StackOverflow answer also considers New-WebServiceProxy and Invoke-RestMethod.

Tobi Obeck
  • 1,918
  • 1
  • 19
  • 31