Reputation: 2246
I'm new to cURL, just got it installed but it seems to only do what it feels like. I'm using the 64 bit version I got from here: http://curl.haxx.se/latest.cgi?curl=win64-ssl-sspi with installation instructions I found here: http://guides.instructure.com/m/4214/l/83393-how-do-i-install-and-use-curl-on-a-windows-machine. Opening a new Powershell window I'm able to use a simple GET request like so:
curl http://localhost:3000
but if I run a POST
curl -d "hello world" http://localhost:3000
it tells me "Invoke-WebRequest : Parameter cannot be processed because the parameter name 'd' is ambiguous. Possible matches include: -DisableKeepAlive -Debug."
Trying to get help I type
curl -h or curl --help
gives me "Invoke-WebRequest : Missing an argument for parameter 'Headers'. Specify a parameter of type 'System.Collections.IDictionary' and try again."
As I mentioned, I'm a cURL newbie but it seems strange that it can do get requests but nothing else. Any ideas what I'm doing wrong?
Windows 7 64 bit Powershell version 4
Upvotes: 139
Views: 120545
Reputation: 440431
tl;dr
Use curl.exe
rather than curl
in order to predictably[1] target the curl executable (C:\Windows\system32\curl.exe
) that comes with recent versions of Windows; doing so works in both PowerShell editions:
# Note the ".exe" part; no longer needed in PowerShell 7
curl.exe -d 'hello world' http://localhost:3000
To elaborate on JPBlanc's answer and provide an alternative solution:
In Windows PowerShell, curl
does not refer to the external curl.exe
program; instead, it is a built-in alias for PowerShell's Invoke-WebRequest
cmdlet.
This alias was removed in PowerShell (Core) 7, where curl
now does refer to curl.exe
by default.
ls
is not an alias on Unix-like platforms, so as not to shadow the native /bin/ls
utility, but still is an alias of Get-ChildItem
on Windows).When in doubt, pass a name to Get-Command
to see what command form it refers to (external executable, alias, cmdlet, function, or script).
While manually removing the alias in Windows PowerShell is one option, it affects the whole session, which may cause scripts (written for Windows PowerShell only) that rely on this alias to fail.
Therefore, the better, per-call solution is to use curl.exe
in calls, i.e. to include the filename extension, .exe
, as shown at the top.
[1] As with invoking any executable specified by name only, it is located via the (first) directory listed int the $env:PATH
environment variable that contains an executable by that name. By default, C:\Windows\system32\curl.exe
should be found, but it's possible to modify $env:PATH
so that a version in a different directory is executed (but not one located in the current directory - the latter applies to cmd.exe
only); for full robustness, use & $env:windir\System32\curl.exe
.
Upvotes: 8
Reputation: 31
Try this
cmd.exe /c curl "https://example.com/file.zip" --user "user:pass" -o file.zip
I was writing a powershell script and needed to use curl inside it, I had the same issue. I used the previous solution and It worked
I don't understand exactly why! but somehow you don't let powershell translate your curl command, you pass it through cmd.
Upvotes: 3
Reputation: 14378
You can execute curl commands with Command Prompt instead of Windows Powershell. Command prompt doesn't alias curl commands like Windows Powershell does.
To open command prompt, hit Win + R
, type cmd
in the input box, <Enter>
.
Upvotes: 5
Reputation: 72680
Your problem is that your are not using the Curl
you installed but a CmdLet called Invoke-WebRequest
.
Just execute :
Remove-item alias:curl
And test your curl again, then store it in your profile.
The explanation is that it exists a native alias to the Invoke-WebRequest
which is a CmdLet that is supposed to deliver a kind of curl service.
From Windows 10 build 17063 and later (April 2018), Curl
is included into Windows, so that you can execute it directly from Cmd.exe or PowerShell.exe. To use it in PowerShell be careful to unalias this CmdLet or explicitly call curl.exe.
Built with Schannel (Microsoft's native TLS engine), libcurl still perform peer certificate verification, but instead of using a CA cert bundle, it uses the certificates that are built into the OS.
Upvotes: 377