gpt4 book ai didi

php - Guzzle ~6.0 多部分和 form_params

转载 作者:可可西里 更新时间:2023-10-31 22:06:38 24 4
gpt4 key购买 nike

我正在尝试像这样同时上传文件和发送 post 参数:

$response = $client->post('http://example.com/api', [
'form_params' => [
'name' => 'Example name',
],
'multipart' => [
[
'name' => 'image',
'contents' => fopen('/path/to/image', 'r')
]
]
]);

但是我的 form_params 字段被忽略了,只有多部分字段出现在我的帖子正文中。我可以用 guzzle 6.0 发送两者吗?

最佳答案

我遇到了同样的问题。您需要将 form_params 添加到 multipart大批。其中“名称”是表单元素名称,“内容”是值。您提供的示例代码将变为:

$response = $client->post('http://example.com/api', [
'multipart' => [
[
'name' => 'image',
'contents' => fopen('/path/to/image', 'r')
],
[
'name' => 'name',
'contents' => 'Example name'
]
]
]);

关于php - Guzzle ~6.0 多部分和 form_params,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30645996/

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