Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Guzzle 6升级后_Php_Laravel_Symfony_Guzzle_Guzzle6 - Fatal编程技术网

Php Guzzle 6升级后

Php Guzzle 6升级后,php,laravel,symfony,guzzle,guzzle6,Php,Laravel,Symfony,Guzzle,Guzzle6,我最近把我的guzzle版本从3升级到了6。下面的调用在3上工作,但现在我需要将其升级到6(因为它不工作)。看完这些文档后,我有点困惑这个新的post请求在Guzzle 6中是如何工作的。这是我用Guzzle 3的旧邮件请求 try { $request = $this->guzzleClient->post( '/login?token='.$this->container->getParamet

我最近把我的guzzle版本从3升级到了6。下面的调用在3上工作,但现在我需要将其升级到6(因为它不工作)。看完这些文档后,我有点困惑这个新的post请求在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();
        }
我如何进行交易,以便它发布请求?

您需要:

$response = $this->guzzle6->post(
    '/login?token='.$this->container->getParameter("token"),
    [
        'json' => $data
    ]
);

return json_decode($response->getBody()->getContents());

Guzzle 6没有
->json()
,所以你必须自己解码它。

看起来这就是你要找的:@OluwatobiSamuelOmisakin-如果这个问题的答案也适用于这里,请将它标记为重复。这是否回答了你的问题@MagnusEriksson不是真的。请给出比“不是真的”多一点的反馈。如果将代码重写为已接受答案中的代码,会发生什么?错误消息?无效的请求?