Guzzle 6 后期升级

我最近将我的 guzzle 版本从 3 更新到 6。以下调用在 3 上工作,但现在我需要将其升级到 6(因为它不工作)。阅读文档后,我有点困惑这个新的帖子请求在 Guzzle 6 中是如何工作的。这是我在 Guzzle 3 中的旧帖子请求


 try

        {

            $request = $this->guzzleClient->post(

                '/login?token='.$this->container->getParameter("token"),

                array(),

                json_encode($data)

            );

            $request->setHeader('Content-Type', 'application/json');

            $response = $request->send();


            return $response->json();

        }

我如何翻译它以便发布请求?


喵喵时光机
浏览 124回答 1
1回答

一只萌萌小番薯

你需要这个:$response = $this->guzzle6->post(    '/login?token='.$this->container->getParameter("token"),    [        'json' => $data    ]);return json_decode($response->getBody()->getContents());Guzzle 6 没有->json()响应,所以你必须自己解码。
打开App,查看更多内容
随时随地看视频慕课网APP