Using cURL on Windows PowerShell

The cURL is a popular command-line tool for sending HTTP requests and checking their responses. cURL also allows for transferring of files to and from servers (in other words, downloading a file from the internet).

Learn to execute the cURL commands from the Windows command prompt or Power Shell window.

1. Check if cURL is Already Installed

    Beginning in Insider Build 17063, Tar and curl are available from the command-line for all SKUs of Windows. That happened back in 2018, so if we have installed Windows recently, there is a high chance we already had curl on our system.

    To verify if cURL is already present, run the following command in command-line or PowerShell.

    curl --help

    If cURL is installed, the above command will show all the different command arguments you can pass to cURL.

    2. How to use cURL on Power Shell

    If cURL is already installed, by default, we can use curl command to invoke the HTTP(s) requests. Note that the default curl command uses Invoke-WebRequest cmdlet provided by Microsoft.

    curl https://google.com

    It will hit the URL and print the response.

    StatusCode        : 200
    StatusDescription : OK
    Content           : <!doctype html><html ...
    RawContent        : HTTP/1.1 200 OK...
    Forms             : {f}
    Headers           : {[Content-Security-Policy-Report-Only...}
    Images            : {@{innerHTML=; innerText=; outerHTML=<IMG id=hplogo title=...
    InputFields       : {@{innerHTML=; innerText=; outerHTML=<INPUT type=hidden ...
    Links             : {@{innerHTML=<SPAN class=gbtb2></SPAN>...
    ParsedHtml        : mshtml.HTMLDocumentClass
    RawContentLength  : 59441

    To use the cURL for other purposes, such as checking help, we must use the curl.exe command.

    > curl.exe --help
    
    # Output
    
    Usage: curl [options...] <url>
     -d, --data <data>          HTTP POST data
     -f, --fail                 Fail fast with no output on HTTP errors
     -h, --help <category>      Get help for commands
     -i, --include              Include protocol response headers in the output
     -o, --output <file>        Write to file instead of stdout
     -O, --remote-name          Write output to a file named as the remote file
     -s, --silent               Silent mode
     -T, --upload-file <file>   Transfer local FILE to destination
     -u, --user <user:password> Server user and password
     -A, --user-agent <name>    Send User-Agent <name> to server
     -v, --verbose              Make the operation more talkative
     -V, --version              Show version number and quit
    
    This is not the full help, this menu is stripped into categories.
    Use "--help category" to get an overview of all categories.
    For all options use the manual or "--help all".

    3. Installing cURL on Older Windows

    3.1. Download cURL Distribution

    Go to the download page of the curl website i.e. https://curl.haxx.se/download.html. Find out the distribution package based on the version of Windows on your machine.

    cURL distributions
    cURL distributions

    3.2. Extract Package

    Extract the package to a desired location. I have extracted it to E:\curl-7.64.1-win64-mingw.

    Extract cURL package
    Extract cURL package

    3.3. Update Windows PATH Variable

    Now update the 'PATH' variable with bin folder location inside the package.

    cURL bin location in windows PATH
    cURL bin location in windows PATH

    3.4. Verify cURL Installation

    Open a new command prompt and hit the following command.

    $ curl –help

    The command will list down all help options.

    cURL help command
    cURL help command

    Now you are good to execute cURL command on Windows as per your requirements.

    Happy Learning !!

    Comments

    Subscribe
    Notify of
    guest
    0 Comments
    Inline Feedbacks
    View all comments

    About Us

    HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

    It also shares the best practices, algorithms & solutions and frequently asked interview questions.

    Our Blogs

    REST API Tutorial

    Dark Mode

    Dark Mode