使用HTTP Controller.php运行带有POST数据的cURL请求时出现500错误

4jb9z9bj  于 2022-11-13  发布在  PHP
关注(0)|答案(1)|浏览(143)

这是我的FlightController.php文件

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::post('/flightdata', [FlightController::class,'data']);

错误:500内部服务器错误

2nbm6dog

2nbm6dog1#

你的代码对我来说是有效的,所以它一定是一些小错误,比如你的控制器里没有use Illuminate\Support\Facades\Http;
请确保在.env文件中设置APP_DEBUG=true,并使用php artisan config:clear清除配置缓存,然后您应该能够看到错误消息。

相关问题