当在POST请求中使用multipart时,Guzzlehttp抱怨标题

时间:2015-12-31 01:32:45

标签: php guzzle

当我尝试使用guzzlehttp 6上传文件时:

class A(object): 
    my_class_variable = 'hello'

我在尝试创建标题时最终收到错误:

$response = $this->client->post($uri, [
        'multipart'    => [
            [
                'name'     => 'File-Name',
                'filename' => $document->name,
                //'Mime-Type' => $document->mime_type,
                'contents' => fopen( $file->getPathname(), 'r' ),
                'headers'  => [
                    'Access-Token' => $this->token,
                ]
            ]
        ]
    ] );

我很难过。

1 个答案:

答案 0 :(得分:2)

尝试

$response = $this->client->post($uri, [
    'multipart' => [
        [
            'name' => 'File-Name',
            'filename' => $document->name,
            'contents' => fopen( $file->getPathname(), 'r' ),
        ],
    ],
    'headers' => [
        'Access-Token' => $this->token,
    ],
]);