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'])...
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);
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');