laravel - Getting 500 error while running cURL Request with POST Data Using HTTP Controller.php
This is my FlightController.php file
public function data(){
// URL
$apiURL = 'http://stageapi.ksofttechnology.com/API/FLIGHT/';
// POST Data
$postInput = [
"TYPE"=> "AIR",
"NAME"=> "GET_FLIGHT",
"STR"=> [
"AUTH_TOKEN"=> "***********************",
"SESSION_ID"=> "",
"TRIP"=> "1",
"SECTOR"=> "D",
"SRC"=> "DEL",
"DES"=> "BOM",
"DEP_DATE"=> "2022-12-10",
"RET_DATE"=> "",
"ADT"=> "1",
"CHD"=> "0",
"INF"=> "0",
"PC"=> "",
"PF"=> "",
"HS"=> "D",
],
];
// Headers
$headers = [
];
$response = Http::withHeaders($headers)->post($apiURL, $postInput);
$statusCode = $response->status();
$responseBody = json_decode($response->getBody(), true);
dd($responseBody); // body response
}
Route File:
Route::post('/flightdata', [FlightController::class,'data']);
Error: 500 Internal Server Error
Answer
Solution:
Your code works for me, so it must be some small error, like maybe you didn't use Illuminate\Support\Facades\Http;
in your controller.
Make sure to set APP_DEBUG=true
in your .env
file and clear your config cache with php artisan config:clear
then you should be able to see the error message.