Guzzle 发出 GET 请求而不是 POST

Guzzle making a GET request instead of POST

我确定这将被标记为重复,但我已经查看了关于同一主题的所有给定问题并尝试了许多建议的解决方案,但它们都没有奏效。

我在一个 laravel 项目中,我有一个 post 请求通过 guzzle 发出。

           $client = new \GuzzleHttp\Client();
           $response = $client->request('POST', $url, [
                'headers' => [
                    'Authorization' => 'Bearer ' . $apiToken,
                    'Accept' => 'application/json',
                    'Content-Type' => 'application/json',
                    'allow_redirects' => false,
                    // 'allow_redirects'=>['strict'=>true]
                ],
                'json' => json_decode($logText, true)
            ]);

我一直在收到回复"message": "The GET method is not supported for this route. Supported methods: POST."

我已经检查过,确实,它正在向上面指定的 $url 发送 GET 请求。

起初我没有那些 allow_redirects 设置,但当我四处搜索时,这两个设置都作为潜在的解决方案提供了。不幸的是,这两个选项都会导致相同的错误消息:The GET method is not supported for this route.

为什么我的 POST 请求变成了 GET 请求?

我也试过 $client->post,结果也变成了 GET 请求。

我还仔细检查了 GET 错误消息实际上并非来自 POST 请求内部:它不是。 POST 路由根本没有被命中。

PHP版本7.2、Laravel版本6.0.2、Guzzle版本6.5.3

检查服务器上的重定向,例如 HTTP -> HTTPS。重定向始终是 GET 请求,这会弄乱非 GET 路由。始终使用正确的协议(例如始终使用 HTTPS)将绕过重定向。