Tuesday, March 07, 2017

Gotchas when using curl on Windows

Curl is a command line tool for transferring data with URL syntax supporting multiple protocols such as HTTP, HTTPS, FTP,etc… It also supports SSL certificates and HTTP commands such as HTTP POST, PUT, GET, etc … It is by default installed on MacOS X but if you have Windows you will need to download it first – I’m using the Curl Win64 – Generic version 7.53.0 build by Viktor Szakats. 

Tip 1: You can use curl to test out REST APIs – unfortunately when I typed curl –XPUT ‘http://localhost/api/scorelead’ – I immediately got an error curl: (1) Protocol 'http not supported or disabled in libcurl.’ A very misleading error message because the way to resolve it on Windows is to just replace the single quotes with double quotes so use curl –XPUT “http://localhost/api/scorelead”

Tip 2: Check out Using Curl for ad hoc testing of RESTful Microservices for some other examples – another gotcha is that when you want to post a JSON payload you will need to escape quotes using this format -  curl -H "content-type:application/json" –XPOST “http:/localhost/api/authenticate” –d "{\"username\":\"user@test.com\",\"password\":\"test123\"}"

Technorati Tags: ,,,

No comments: