首页 > 解决方案 > 我用 GuzzleHttp 请求无法解决 PSR 请求错误

问题描述

在我的 Laravel 7.6 应用程序(我本地操作系统的http://local-votes.com上的 pt 主机)api 中实现外部 api 我想从我的其他 Laravel 6.17.1 应用程序发出测试请求并在此处阅读:https:/ /laravel.com/docs/7.x/passport 将授权码转换为访问令牌

我尝试使用这个例子:

        $http = new \GuzzleHttp\Client;

        $client_id= 3;  // client ID I made in my host app
        $client_secret= 'XXX'; // client secret I made in my host app

        $host= 'http://local-votes.com';
        $response = $http->post($host.'/oauth/token', [
            'form_params' => [
                'grant_type' => 'authorization_code',
                'client_id' => $client_id,
                'client_secret' => $client_secret,
                'redirect_uri' => $host.'/votes',
                'code' => 'code',
//                'code' => $request->code,
            ],
        ]);

但我得到了错误:

Illuminate\Contracts\Container\BindingResolutionException: Unable to resolve PSR request. Please i (truncated...)
 {"userId":5,"exception":"[object] (GuzzleHttp\\Exception\\ServerException(code: 500): Server error: `POST http://local-votes.com/oauth/token` resulted in a `500 Internal Server Error` response:

另外我不确定我为字段“client_secret”和“code”提供了哪些值?这可能是问题吗?

如何解决此错误?

谢谢!

标签: laravelguzzle

解决方案


在提供程序应用程序上安装包 nyholm/psr7 解决了这个问题!


推荐阅读