Running cURL on 64 bit Windows - windows

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

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.

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>.

Related

Curl Upload-File inside Shell Runner

I am trying to upload a single file via curl from within a gitlab-shell-runner.
Basically I need to use this command:
curl --user <user:password> --insecure --upload-file <file> https://example.com
Following error is shown:
Invoke-WebRequest : A positional parameter cannot be found that accepts argument "<user:password>"
Which adjustments do I need to make, to run this inside gitlab-ci?
I have already tried to use a variable for the address and different variation of quotations.
Thank you in Advance!
As mentioned in "Running cURL on 64 bit Windows" you are running a CmdLet called Invoke-WebRequest, which has a curl alias in Powershell.
Start by removing it:
Remove-item alias:curl
Then check if your script does call the actual curl command (or you might need to call it explicitly).
Or: use Invoke-WebRequest (aliased 'curl') with a Basic $encodedCredentials header.

curl command in git-bash

I have a script written in bash and tested working in Linux (CentOS 7) and on MacOS. The script uses cURL to interact with a REST API compliant data platform (XNAT).
I was hoping that Windows users could use the same script within git-bash that comes packaged with Git for Windows. Unfortunately there seems to be an issue when using cURL in git-bash.
The first use I make of cURL is to retrieve a JSESSION cookie:
COOKIE=`curl -k -u $USERNAME https://theaddress/JSESSION`
On Linux, this asks the user for password and stores the cookie in COOKIE.
In git-bash, issuing the command hangs, until using a "ctrl + C" to interrupt it. Strangely at that point the query message for the password is displayed, but too late, the script has terminated.
I have a suspicion that this may have to do with CR or LF issues, but cannot find some info I understand regarding this.
Any pointers would be welcome !
Thank you
EDIT:
It appears the above command works fine if I pass the password in the command like this:
COOKIE=`curl -k -u $USERNAME:$PASSWORD https://theaddress/JSESSION`
However, as pointed here:
Using cURL with a username and password?
I would rather avoid having the user typing their password as a command argument.
So the question is now "why is cURL not prompting for a password when I use the first command?" when in git-bash on Windows, while that command behaves as expected in Linux or MacOS:
COOKIE=`curl -k -u $USERNAME https://theaddress/JSESSION`
Ending up replying to my own question, hope this may be useful to someone else.
It appears this issue is a known problem when running cURL from within git-bash, according to this thread:
https://github.com/curl/curl/issues/573
In particular, see the answer of dscho on 30 Dec 2015:
The problem is the terminal emulator we use with Git Bash since Git for Windows 2.5, MinTTY.
This terminal emulator is not associated with a Win32 Console, therefore the user does not see anything when cURL wants to interact with the user via said Console.
This issue has a workaround, which is documented here:
https://github.com/git-for-windows/build-extra/blob/master/ReleaseNotes.md#known-issues
The workaround is to run curl via winpty as follows:
winpty curl [arguments]
Not an issue with CR or LF after all.
Soooo, git-bash may not be the magic-bullet (tm) to run my bash scripts in Windows with zero effort. Sigh...

Proxy Settings for Windows 7 Command Prompt

I am trying to use cURL in the Command Prompt, but I dont understand where I have problems. I have been told that I need to configure a proxy tothe Command Prompt so that it can access the sites I am calling on.
This is what I want to run: curl -glob "api.fda.gov/drug/event.json?&search=receivedate:[20040101+TO+20150101]&limit=1"
I have cURL installed, but always face errors because it is not connecting. Is there a simple way to set up a proxy for/through the Command Prompt in Windows 7?
I also do not have admin rights, so I cannot change the system settings.
You can set your proxy using a set command in windows:
set http_proxy=http://<yourproxyaddress>:<port>
Then you can connect your curl requests to external sites.
Some proxies require specific authentication headers to be set, so be aware of those as well. In my case, it's --proxy-ntlm in the example below:
curl -x webproxy.net:8080 -U usernaname:password http://google.com --proxy-ntlm
But there're other options:
--proxy-digest and --proxy-negotiate
Lastly, cURL has a super friendly doc page, so be sure to check it out.

command line web browsing

Is there a way to perform http commands GET/PUT/SET whatever via a command line in ubuntu or windows xp? Preferably without installing 3rd party products. Being that http is text based I thought it would be alot easier to run in the cmd line.
I've been able to get what I want out of GET in ubuntu in bash via
$wget google.com
$cat index.html
This is kinda clunky. It would be nice to pipe the output or something, but even that isn't straight forward. C programs are fine too. I'm trying to do something like what we get with Fiddler, but more basic.
telnet google.com 80
GET / HTTP/1.0
Host: google.com
You have to hit return twice after the Host line. It doesn't get any more basic.
If you are familiar with HTTP use telnet.
If you are looking for a browser take a look for Links.
Although it requires a 3rd party tool, these days I use curl. The -X option allows me to specify the HTTP verb. Windows has a few bash clients that allow you to run curl including Cygwin.
Sample Execution
$ curl -H "Content-Type: application/json" -X POST -d '{value: "600"}' http://localhost:8888/my/endpoint

Run cURL commands from Windows console

Is there a way to install cURL in Windows in order to run cURL commands from the command prompt?
If you are not into Cygwin, you can use native Windows builds. Some are here: curl Download Wizard.
Update: Curl is now included in Windows, no need to run it via PowerShell.
First you need to download the cURL executable. For Windows 64bit, download it from here and for Windows 32bit download from here
After that, save the curl.exe file on your C: drive.
To use it, just open the command prompt and type in:
C:\curl http://someurl.com
If you have Git installed on windows you can use the GNU Bash.... it's built in.
https://superuser.com/questions/134685/run-curl-commands-from-windows-console/#483964
Update: Curl is now included in Windows, no need to run it via PowerShell.
Folks that don't literally need the curl executable, but rather just need to e.g. see or save the results of a GET request now and again, can use powershell directly. From a normal command prompt, type:
powershell -Command "(new-object net.webclient).DownloadString('http://example.com')"
which, while a bit wordy, is similar to typing
curl http://example.com/
in a more Unix-ish environment.
More information about net.webclient is available here: WebClient Methods (System.Net).
UPDATE: I like how ImranHafeez took this one step further in this answer. I'd prefer a simpler cmd-script however, maybe creating a curl.cmd file containing this:
#powershell -Command "(new-object net.webclient).DownloadString('%1')"
which could be called just like the Unix-ish example above:
curl http://example.com/
If you use the Chocolatey package manager, you can install cURL by running this command from the command line or from PowerShell:
choco install curl
With Windows 10 Insider build 17063 curl is available in the cmd and powershell since early 2018.
Create batch file in windows and enjoy with cURL in windows :)
#echo off
echo You are about to use windows cURL, Enter your url after curl command below:
set /p input="curl "
cls
echo %input%
powershell -Command "(new-object net.webclient).DownloadString('%input%')"
pause
Currently in Windows 10 build 17063 and later, cURL comes by default with windows. Then you don't need to download it and just use curl.exe.
Visit download page https://curl.haxx.se/download.html - it's incredible
Choose your sytem in list
Don't forget SSL support, it's obvious now, e.g. for https
Unpack curl.exe and .crt to C:\Windows\System32
Restart cmd
Enjoy > curl https://api.stackexchange.com
p.s. If you want another folder to store executable check your paths > echo %PATH%
it should work perfectly fine if you would download it from
--http://curl.haxx.se/dlwiz/?type=bin&os=Win64&flav=MinGW64 -- FOR 64BIT Win7/XP OR from http://curl.haxx.se/dlwiz/?type=bin&os=Win32&flav=-&ver=2000%2FXP --- FOR 32BIT Win7/XP just extract the files to c:/Windows and run it from cmd
C:\Users\WaQas>curl -v google.com
* About to connect() to google.com port 80 (#0)
* Trying 173.194.35.105...
* connected
* Connected to google.com (173.194.35.105) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.28.1
> Host: google.com
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 301 Moved Permanently
< Location: http://www.google.com/
< Content-Type: text/html; charset=UTF-8
< Date: Tue, 05 Feb 2013 00:50:57 GMT
< Expires: Thu, 07 Mar 2013 00:50:57 GMT
< Cache-Control: public, max-age=2592000
< Server: gws
< Content-Length: 219
< X-XSS-Protection: 1; mode=block
< X-Frame-Options: SAMEORIGIN
< X-Cache: MISS from LHR-CacheMARA3
< X-Cache-Lookup: HIT from LHR-CacheMARA3:64003
< Connection: close
<
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
here.
</BODY></HTML>
* Closing connection #0
Install Git for windows
Then use git bash to run curl commands.
Install git command line from here. When you install git in windows you will automatically get curl with it. You can check the installed version of curl using curl --version like this.
This is a sample curl request which sends a string in a JSON object and get it encoded.
curl https://api.base62.io/encode \
--request POST \
--header "Content-Type: application/json" \
--data '{ "data": "Hello world!" }'
I was able to use this site to easily download and install curl on my Windows machine. It took all of 30 seconds. I'm using Windows 7 (w/ Admin privelages), so I downloaded curl-7.37.0-win64.msi from http://curl.haxx.se/download.html.
Also, don't forget to restart your console/terminal after you install curl, otherwise you will get the same error messages.
I have also found that if I put the cygwin bin on my windows path I can run curl from a windows command line. It also will give you access to things like ls and grep
Assuming you are new to the game or are unable to install software because of security restrictions, you could use Scoop to install curl. From a powershell or command window run the following commands. Note this assumes that you have Powershell v3.0+.
The other cool advantage here is that this installs the software for just the current user.
Set execution exception
Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser
Install Scoop
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
Install curl. You may see a warning about a missing hash, but you should see a final message that cURL was installed successfully
scoop install curl
Test the install of curl
curl -L https://get.scoop.sh
From Windows Command Prompt, run curl through Git Bash
"C:\\Users\\sizu\\AppData\\Local\\Programs\\Git\\bin\\sh.exe" --login -i -c "curl https://www.google.com"
Go to curl Download Wizard
Select curl executable
Select Win32 or Win64
Then select package for it(Eg generic/cygwin) as per your requirement
Then you will have to select version. You can select unspecified.
This will directly take you to download link which on click will give you popup to download the zip file.
Extract the zip to get the executable. Add this folder in your environment variables and you are done. You can then execute curl command from cmd.
Download the .exe file from https://cygwin.com/install.html for cygwin (a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows).
Run the .exe file.
While installing you will get in a step to select packages. In the select package window --> change the view to "Not installed" and search for curl. click on the necessary packages to install by clicking on the "new" column for the package --> you can see the version number and then click next. ( see the image attached below)
After finishing the installation click on the cygwin to open the curl console on windows and work on curl commands.
I am may be bit late for this, but I am able to resolve my issue of curl at cmd for windows 10.
I got help from below video tutorial https://www.youtube.com/watch?v=qlTVMuONazs
Here is some explanation
Step 1: go to https://curl.haxx.se/download.html
Step 2: Search "Win64 - Generic" and download "Win64 x86_64 7zip" by "Darren Owen"
Step 3: unzip the download file and install the certificate "ca-bundle.crt" do not touch curl.exe
Step 4: in windows go to "Control Panel" -> "System" -> "Advance system settings
"
Step 5: click on Envirnoment variables
Step 6: In System variable click on "Path" and paste the path of the file folder in my case it is "C:\curl\curl_7_53_1_openssl_nghttp2_x64"
And you are done.
Don't Forgot to restart you system for one time
Simplest answer:
(1) Download the curl binary here: https://curl.haxx.se/download.html (see the binary for your OS). Example:
(2) Create a folder "C:\curl" then unzip all there
(3) Edit the system variable called "Path" by adding ";C:\curl\bin" in the end. Finished.
Obs.: I've seen some guys telling to add ";C:\curl" but this way it's not possible to access curl.exe.
For anyone looking for a quick solution, after having standard installed cygwin but finding out curl did not work on a win 10 x64 platform:
Downloading this retired repository, extracting it and running:
git-cmd.bat
Worked like a charm. I assume it has the pre-installed option for curl.
I've used MobaXterm and it runs curl command properly.

Resources