Guzzle响应问题

Guzzle response issue

我正在使用 Guzzle 6 将 URL 发送到远程服务器。如果我尝试使用 Postman 发送相同的 URL,我将收到返回生成的报告...这意味着 URL 并且连接正常。每次我 dd file_put_contents,我都会收到 false。如果我为 $response 放置一些随机字符串,一切正常。执行我的代码会给我 200 OK,但如前所述,我总是会收到带有 dd 的 false。

$this->client = new Client();
    $response = $this->client->post($url);

    dd(file_put_contents($this->filename, $response));

$response 单独使用是行不通的,因为这是一个对象。

您需要使用 $response()->getBody() 来获取响应的内容。

也可能值得将其转换为字符串:dd(file_put_contents($this->filename, (string)$response->getBody()));