Correct way to set Bearer token with CURL

前端 未结 7 868
悲哀的现实
悲哀的现实 2020-11-30 22:12

I get my bearer token from an API end point and set the following:

$authorization = \"Bearer 080042cad6356ad5dc0a720c18b53b8e53d4c274\"

Nex

7条回答
  •  不思量自难忘°
    2020-11-30 22:50

    Guzzle example:

    use GuzzleHttp\Client;
    use GuzzleHttp\RequestOptions;
    
    $token = 'your_token';
    
    $httpClient = new Client();
    
    $response = $httpClient->get(
        'https://httpbin.org/bearer',
        [
            RequestOptions::HEADERS => [
                'Accept' => 'application/json',
                'Authorization' => 'Bearer ' . $token,
            ]
        ]
    );
    
    print_r($response->getBody()->getContents());
    

    See https://github.com/andriichuk/php-curl-cookbook#bearer-auth

提交回复
热议问题