Command line curl REST authentication

Sometimes you want to test out REST calls from the command line. How to handle the dual realm Authorization headers that Datacentre requires? --user will not work because curl will only accept one such parameter, so you need to specify the Authorization headers yourself.

Here's a sample of how to do that (Mac, Linux)

curl --header "Authorization: Basic `echo -n 'Fold/Fold2:Datacentre:FOLDERPASS' | openssl base64`" --header "Authorization: Basic `echo -n 'Admin:Document:DOCPASS' | openssl base64`" "http://server:6710/REST/Fold%2fFold2%2fAcme3.moneyworks/evaluate/expr=name"

Even better, put both Authorizations in a single header, separated by comma-space

curl --header "Authorization: Basic `echo -n 'root:Datacentre:FOLDERPASS' | openssl base64`, Basic `echo -n 'Admin:Document:DOCPASS' | openssl base64`" "https://server:6710/REST/Acme.moneyworks/evaluate/expr=name"

see also http://cognito.co.nz/developer/accessing-restserver-from-php/

Posted in CLI, REST | Comments Off on Command line curl REST authentication