cURL and Wget alternatives for Windows Command Prompt with Powershell Some great Powershell alternatives to the Linux GNU Wget and cURL type command-line utilities using the System.Net namespace

cURL and Wget alternatives for Windows Command Prompt with Powershell

Today I had to find a way to execute a repeatable series of HTTP requests addressed to a Web Server from a Windows 10 machine.

If it were a Linux OS, I could've used cURL from a Terminal window in the following one-liner:

Unfortunately, there's nothin close to cURL in Windows, except for the BITSAdmin Tool - a command-line tool that you can use to create download or upload jobs and monitor their progress. However, BITSAdmin is designed to work with jobs and tasks, meaning that you have to create a job first, then append one or more tasks to it - which I found to be overkill for my current scenario.

Luckily enough there is a quicker alternative, thanks to the System.Net.WebClient class that can be invoked using Powershell.

cURL

All we need to do is to create a cURL.ps1 file and fill it with the following contents:

To get the contents as a string, or

In case we want to retrieve the URL as a byte array.

Wget

If we want to emulate the Wget command instead, we can do the following with a wget.ps1 file:

Ignore SSL warnings

In the unlikely scenario that we need to send our request(s) to a HTTPS website with an invalid certificate - which could easily be the case for locally-hosted resources, as they often rely to a self-signed certificate - we can use the ServicePointManager.ServerCertificateValidationCallback property provided by the System.Net namespace to disable the SSL trust requirements.

This can be done by adding the following line to any of our previous commands:

Here are the updated commands:

That's it for now: happy requests!

 

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.