Search code examples
laravelhttp-headershttpclient

Send header in get request using Laravel Http Client


I want to send Header using Http Client in get() method, let me share my code with you.

Http::get('https://subscriptions.zoho.com/api/v1/plans')->withHeader(['Authorization', $zohoToken]);

I want to pass these headers but don't know how to pass headers in http::get() request

$header = array(
         'Authorization: Zoho-oauthtoken ' . $accessToken,
         'Content-Type: application/json' );

Solution

  • Use here withHeaders method

    Http::withHeaders([
         'Authorization' =>  'Zoho-oauthtoken ' . $accessToken,
         'Content-Type' => 'application/json' 
    ])->get('https://subscriptions.zoho.com/api/v1/plans');