gpt4 book ai didi

php - Laravel 中的 Guzzle 不断加载,不返回值

转载 作者:行者123 更新时间:2023-12-04 15:55:52 27 4
gpt4 key购买 nike

我使用 Laravel passport 进行 API 身份验证。我有两条路线 /API/登录和 /oauth/ token

因为我不能硬编码我的客户端 ID 并且登录从 JS 接收并且参数和客户端 ID 在登录方法(laravel)中被硬编码,我尝试使用 Guzzle(6.0)将值发布到 oauth/token(POST 请求).

我关注了一个 youtube 视频,它在那里工作但不是我的。我正在使用 5.6,不确定视频中的哪个版本。有人可以帮忙吗?

下面是视频

https://www.youtube.com/watch?v=HGh0cKEVXPI&t=838s

下面是代码

$http = new GuzzleHttp\Client();
$request = $http->post(URI, '/oauth/token', [
'form_params' => [
'username' => 'bar',
'password' => 'xxxxxx',
'client_id' => 2,
'grant_type' => 'password',
'client_secret' => '00000000000000000'
]
]);

return $request;

最佳答案

您没有得到仅返回 guzzle $request 初始化的响应,因此添加 getBody()

   $http = new GuzzleHttp\Client();
$request = $http->post(URI, '/oauth/token', [
'form_params' => [
'username' => 'bar',
'password' => 'xxxxxx',
'client_id' => 2,
'grant_type' => 'password',
'client_secret' => '00000000000000000'
]
]);

return $request->getBody();

关于php - Laravel 中的 Guzzle 不断加载,不返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51724281/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com