What is the correct way to sent json as multipart form in guzzle. From the code below it should be possible to iterate through userComment
from the posted page. For eg: userComment[0]
should give {'name' => 'Jon', 'comment' => 'jons comment'}
and userComment[0]['name']
should print Jon
. But it is not working.
$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"}'
]
]
]);
Documentation says that Contents
should be of string, hence 'contents' => '{name: "mike", comment: "okay"}'
will work, but then I will have to do $data = json_encode(userComment[1])
to get $data['name']
as mike
which doesn't looks like the correct way of doing. Any help, thanks!