如何为多部分 POST 请求设置自定义边界?以下请求选项配置不起作用。
'headers' => ['Content-Type' => 'multipart/form-data; boundary=CUSTOM_BOUNDARY']
Guzzle 使用 psr7 将多部分表单字段组合到请求正文中。处理自定义边界的最正确方法是使用GuzzleHttp\Psr7\MultipartStream.
$boundary = 'my_custom_boundary';
$multipart_form = [
[
'name' => 'upload_id',
'contents' => $upload_id,
],
[
'name' => '_uuid',
'contents' => $uuid,
],
...
];
$params = [
'headers' => [
'Connection' => 'close',
'Content-Type' => 'multipart/form-data; boundary='.$boundary,
],
'body' => new GuzzleHttp\Psr7\MultipartStream($multipart_form, $boundary), // here is all the magic
];
$res = $this->client->request($method, $url, $params);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)