cURL is a computer software project that provides a library and command-line tool for transferring data using various network protocols. The name stands for “URL client,” and it was first released in 1997.
If you’ve ever wondered what the equivalent of the cURL command is in Powershell, you’ve come to the right place!
cURL in Powershell
Running a cURL in Powershell is a matter of seconds. The command is Invoke-WebRequest but for simplicity an alias is included that has the same nomenclature as the Unix command.
First, after opening a Powershell window, we must define the eventual content of the request we want to make. In this example we are going to execute a POST request containing some information of a hypothetical message to be sent to a recipient:
With this command, we are going to create a block of data containing 2 example parameters: recipient and message.
At this point, we just have to send the message to a listening server.
Let’s suppose that my server is reachable at IP address 192.168.178.31, port 8080 and that there is a resource called sendmessage ready to receive my requests and send the messages to the specified user.
This is possible thanks to the following command:
as I told you earlier, we use an alias that has the same syntax of the cURL command, where, with the -Uri option we specify the address to refer to, through the -Method option we specify the type of request, and with the -Body option we pass the body of the request.
In case of a GET request, it will not be necessary to pass any -Body, instead we can execute the request with the following command:
In this short article we have seen how to use cURL in Powershell. This command allows you to transfer data using different communication protocols. It is often used to send POST and GET requests in HTTP. In Powershell, cURL is an alias of Invoke-WebRequest that exposes the same syntax as the Unix command.