Site icon Ryadel

cURL and Wget alternatives for Windows Command Prompt with Powershell

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!

 

Exit mobile version