gpt4 book ai didi

php - Guzzle 不从 Form MultiPart 发送标题

转载 作者:搜寻专家 更新时间:2023-10-31 21:23:17 25 4
gpt4 key购买 nike

我正在使用 "guzzlehttp/guzzle": "~6.0", 并尝试将文件发布到 API 端点。使用 RequestBin 时文件发布正常,但 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
]);

关于php - Guzzle 不从 Form MultiPart 发送标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41785861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com