Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Hadayat's avatar

Send header in get request using Laravel Http Client

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

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

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

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

I check it for some reason my headers are not, maybe I am doing something wrong How I check that header is not set

var_dump($plans->header('Authorization'));

In postman, the same thing is working. I am attaching the screen shot of postman

'https://drive.google.com/file/d/1_-uVYX4K0WdSUbKW3eIIZl7m68vhI_df/view?usp=sharing'
0 likes
13 replies
Nakov's avatar
Nakov
Best Answer
Level 73

I think your syntax is wrong only:

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

and the content type by default is sent as the one you need.

Nakov's avatar

@Hadayat here is a test I wrote:

Http::fake();

Http::withHeaders([
        'X-First' => 'foo',
       'Authorization' => 'testing',
])->get('https://catfact.ninja/facts');

Http::assertSent(function (Request $request) {
   return $request->hasHeader('X-First', 'foo') && $request->hasHeader('Authorization', 'testing') &&
       $request->url() == 'https://catfact.ninja/facts';
});

and it passed.. if I write testing1 in the expectation it fails of course. So seems like the headers are sent with the GET request.

Hadayat's avatar

@Nakov Appreciate that you wrote test and prove that it's working. Can you please tell me why it's not working in my case? It's working in Postmen but here it's not working, any idea about this?

Sinnbeck's avatar

@Hadayat How can you tell its not working? An error?

Can you show the exact set up in postman?

Hadayat's avatar

@Sinnbeck I am sending the request at it throwing the exception that you are not authroized. I also check it by using header method that header is in request or not by using this $request->header('Authorization')

Nakov's avatar

@Hadayat I don't get it since I cannot test using your code.. I am not sure if this $zohoToken is empty maybe..

Try this:

Http::withHeaders(['Authorization' => 'testing'])->get('https://subscriptions.zoho.com/api/v1/plans');

is there still no token sent?

Which version of Laravel are you using?

Hadayat's avatar

@Nakov I am using Laravel 9, and I am dd the authorization and it's returning the empty but when I removed this it working perfectly. Thank you for your precious time, it's mean a lot to me.

Please or to participate in this conversation.