Search code examples
phpapicurlunirest

what is curl -u equivalent in php unirest


what is curl -u equivalent in php unirest

Blockscore API:

$ curl https://api.blockscore.com/people \
  -u sk_test_n5049aa6053c9a0217bea78070fbf501: \
  --header "Accept: application/vnd.blockscore+json;version=4"

Api key: sk_test_n5049aa6053c9a0217bea78070fbf501

I want to try this out in Unirest. but what is -u? is it a header or a post?


Solution

  • The -u flag for cURL is used to set the credentials for HTTP Basic authentication. The provided credentials will be base64-encoded and presented in the "Authorization" header as in:

    Authorization: Basic c2tfdGVzdF9uNTA0OWFhNjA1M2M5YTAyMTdiZWE3ODA3MGZiZjUwMTo=
    

    So it is a header.

    In unirest you should be able to use:

    Unirest\Request::auth('sk_test_n5049aa6053c9a0217bea78070fbf501', '');