无法在 Laravel 应用程序上发出 http POST 请求 [关闭]

问题描述 投票:0回答:0

当我尝试发送 http POST 请求以获取护照令牌时,该请求无法处理。

$response = Http::asForm()->post('http://localhost:8000/oauth/token', [
                'grant_type' => 'password',
                'client_id' => env('PASSPORT_CLIENT_ID', null),
                'client_secret' => env('PASSPORT_CLIENT_SECRET', null),
                'username' => $request->email,
                'password' => $request->password,
                'scope' => '',
            ]);

            return $response->json();

我的项目在端口 8000 上运行。但是我无法使用端口 8000 发出 http post 请求。


相反,我需要在 8000 和 8001 上运行相同的项目才能获得结果。

$response = Http::asForm()->post('http://localhost:8001/oauth/token', [
                'grant_type' => 'password',
                'client_id' => env('PASSPORT_CLIENT_ID', null),
                'client_secret' => env('PASSPORT_CLIENT_SECRET', null),
                'username' => $request->email,
                'password' => $request->password,
                'scope' => '',
            ]);

            return $response->json();

这将返回预期的输出。但是我需要通过仅在单个端口上运行我的项目来获得预期的输出。有人请帮助我。

http://localhost:8000/api//token/expiry 这个 url 在控制器中调用一个函数,它包含一个 http post 请求 http://localhost:8000/oauth/token。但它行不通。因为两个请求都包含相同的端口号 8000.

php laravel laravel-9 laravel-passport
© www.soinside.com 2019 - 2024. All rights reserved.