Guzzle 未从 Form MultiPart 发送 Headers

Guzzle Not Sending Headers From Form MultiPart

我正在使用 "guzzlehttp/guzzle": "~6.0", 并尝试将文件 post 发送到 API 端点。使用 RequestBin 时文件 post 没问题,但是 API 没有得到它需要的 header。 Header 也不会发送到 Request bin。根据文档,我需要做一个关联数组的数组。 http://docs.guzzlephp.org/en/latest/quickstart.html#post-form-requests

但是,这不起作用。这是 Guzzle 请求:

$client = new GuzzleHttp\Client(['base_uri' => '127.0.0.1:3000']);
        $response = $client->request('POST', '/process', [
            'multipart' => [
                [
                    'name'     => 'file',
                    'contents' => $file,
                    'bucketName' => 'test',
                    'headers'  => ['X-API-Key' => 'abc345']
                ],
            ]
        ]);

它没有发送 header 我做错了什么?

非常感谢,

乔什

Headers 是一个 $option,这意味着它必须与 multipart 处于同一级别。

<?php
      $response = $client->request('POST', '/process', [
        'multipart' => [
            [
                'name' => 'file',
                'contents' => 'test',
                'bucketName' => 'test',
            ],
        ],
        'headers' => ['X-API-Key' => 'abc345'] // <------- HERE
    ]);