从响应流中读取到非活动超时

时间:2019-06-10 10:20:32

标签: httpclient postman symfony4 fosoauthserverbundle

尝试使用symfony4实现REST API oauth2.0身份验证。 / oauth / v2 / token道路工作正常,但是,我正在尝试创建/ api / login道路,该道路将从请求中获取凭据,并向/ oauth / v2 / token建立一个Httpclient-> request()并获得访问权限令牌并返回给用户。

这是我的代码:

 childs: {
        Sincerity: [
          {
            id: 1,
            text: "Down-to-earth"
          },
          {
            id: 2,
            text: "Honest"
          },
          { ... }
        ],
        Excitement: [
          {
            id: 12,
            text: "Daring"
          },
          {
            id: 13,
            text: "Sprited"
          },
          { ... }
        ],
        Competence: [
          {
            id: 23,
            text: "Reliable"
          },
          {
            id: 24,
            text: "Intelligent"
          },
          { ... }
         ]

但是自从我出现此错误后,我无法解决:

public function login(Request $request)
    {
        //dd($request->getMethod());
        $method = $request->getMethod();
        $grantType = $request->query->get('grant_type');
        $clientId = $request->query->get('client_id');
        $secretId = $request->query->get('client_secret');
        $username = $request->query->get('username');
        $password = $request->query->get('password');
        $path = $_SERVER['API_BASE_URL'] . 'oauth/v2/token';

        $httpClient = HttpClient::create();
        //dd($httpClient);
        $response = $httpClient->request($method, $path, [
            // these values are automatically encoded before including them in the URL
            'query' => [
                'grant_type' => $grantType,
                'client_id' => $clientId,
                'client_secret' => $secretId,
                'username' => $username,
                'password' => $password,
            ],
        ]);

        $statusCode = $response->getStatusCode();

        $contentType = $response->getHeaders()['content-type'][0];

        $content = $response->getContent();

        $content = $response->toArray();


        return $content;

    }

即使使用Guzzle,我也尝试更新httpclient版本,同样的错误。

0 个答案:

没有答案