Php 用guzzle下载pdf

Php 用guzzle下载pdf,php,guzzle,php-5.4,Php,Guzzle,Php 5.4,我想下载一个带有guzzle的pdf文件。这可能吗 我尝试了以下代码: $response=$this->client->post(self::API\u BASE\u URL.self::API\u LABEL\u URL, [ “未来”=>正确, “json”=>[$this->json], 'headers'=>['Content-Type'=>'application/json','Accept'=>'application/pdf'], “查询”=>[ “返回类型”=>“pdf”, “

我想下载一个带有guzzle的pdf文件。这可能吗

我尝试了以下代码:

$response=$this->client->post(self::API\u BASE\u URL.self::API\u LABEL\u URL,
[
“未来”=>正确,
“json”=>[$this->json],
'headers'=>['Content-Type'=>'application/json','Accept'=>'application/pdf'],
“查询”=>[
“返回类型”=>“pdf”,
“x-api-key”=>$this->apiKey
],
]);
我得到

[body] => GuzzleHttp\Stream\Stream Object(
[stream:GuzzleHttp\Stream\Stream:private] => Resource id #120
[size:GuzzleHttp\Stream\Stream:private] => 649
[seekable:GuzzleHttp\Stream\Stream:private] => 1
[readable:GuzzleHttp\Stream\Stream:private] => 1
[writable:GuzzleHttp\Stream\Stream:private] => 1
[uri:GuzzleHttp\Stream\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Stream\Stream:private] => Array
但是我不知道如何处理这个资源id来保存pdf文件。
我使用guzzle 5.3和PHP 5.4,没有更新PHP版本的选项。

您可以使用guzzlesink选项下载文件-


更多示例-

为什么不可能?代码有什么问题?我不知道下一步该怎么做。下一步该怎么做?什么还不起作用?
$pdfFilePath = __DIR__ . '/resource/file.pdf'; // specify your path
$pdfFileResource = fopen($pdfFilePath, 'w+');

$this->client->post(
    self::API_BASE_URL . self::API_LABEL_URL,
    [
        'future' => true,
        'json' => [$this->json],
        'headers' => [
            'Content-Type' => 'application/json', 
            'Accept' => 'application/pdf'
        ],
        'query' => [
            'return-type' => 'pdf',
            'x-api-key'   => $this->apiKey
        ],
        'sink' => $pdfFileResource
    ]
);