5

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' );
0

2 Answers 2

15

Use here withHeaders method

Http::withHeaders([
     'Authorization' =>  'Zoho-oauthtoken ' . $accessToken,
     'Content-Type' => 'application/json' 
])->get('https://subscriptions.zoho.com/api/v1/plans');
Sign up to request clarification or add additional context in comments.

2 Comments

I used this method earlier but it's not passing the token. In PostMan, my logic is working but In HTTP it's not working, return invalid auth token, Is there any way to check that headers are properly set.
I dd() the authorization header it's not set.
0

You can use Http::withToken()

3 Comments

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
For anybody looking: laravel.com/docs/10.x/http-client#bearer-tokens Bearer Tokens If you would like to quickly add a bearer token to the request's Authorization header, you may use the withToken method: $response = Http::withToken('token')->post(/* ... */);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.