Laravel call internal API from controller using post and passing basic auth authorization to request

I am calling internal API route from controller but unable set headers using laravel 8

$request = Request::create('/api/login/', 'POST',['id' => '1']);
$request->headers->set('Authorization','Basic YWJjOjEyMw==');//not working
$response = Route::dispatch($request);
print_r($response);
3

1 Answer

Have you tried using the Http facade for that?

use Illuminate\Support\Facades\Http;
$response = Http::withHeaders(['Authorization' => 'Basic ...'])->post('/api/login');
$json = $response->json();
$specific_field = $response->json('specific_field');
3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like