curlauthorizationbasic-authentication

Basic authorization command for curl


How do I set up the Basic authorization using Base64 encoded credentials?

I tried the below two commands, but of no use. Please suggest me the correct variant.

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  

Solution

  • Use the -H header again before the Authorization:Basic things. So it will be

    curl -i \
        -H 'Accept:application/json' \
        -H 'Authorization:Basic BASE64_string' \
        http://example.com
    

    Here, BASE64_string = Base64 of username:password