basic authorization command for curl

Amit Sharad picture Amit Sharad · Dec 27, 2013 · Viewed 110k times · Source

How do I set up the basic authorization using 64 encoded credentials ? I tried below the two commands but of no use , please suggest.

curl -i -H 'Accept:application/json' Authorization:Basic <username:password> http://example.com
curl -i -H 'Accept:application/json' Authorization:Basic.base64_encode(username:password) http://example.com  

Answer

deltheil picture deltheil · Dec 28, 2013

How do I set up the basic authorization?

All you need to do is use -u, --user USER[:PASSWORD]. Behind the scenes curl builds the Authorization header with base64 encoded credentials for you.

Example:

curl -u username:password -i -H 'Accept:application/json' http://example.com