在guzzle中将json作为multipart表单发送的正确方法是什么?从下面的代码中,应该可以从发布的页面中迭代userComment
。例如:userComment[0]
应该{'name' => 'Jon', 'comment' => 'jons comment'}
而userComment[0]['name']
应该打印Jon
。但它没有用。
$response = $client->request('POST', $url, [
'multipart' => [
[
'name' => 'action',
'contents' => 'addComment',
],
[
'name' => 'userComment',
'contents' => ['json' => ['name' => 'Jon', 'jons comment' => 'Please']]
],
[
'name' => 'userComment',
'contents' => '{name: "mike", comment: "mikes comment"}'
]
]
]);
文档说Contents
应该是字符串,因此'contents' => '{name: "mike", comment: "okay"}'
会起作用,但我必须$data = json_encode(userComment[1])
才能$data['name']
为mike
这看起来不像是正确的做法。任何帮助,谢谢!