Php 使用JSON的HTTP post
在guzzle中以多部分形式发送json的正确方法是什么。从下面的代码中,应该可以从发布的页面迭代Php 使用JSON的HTTP post,php,guzzle,Php,Guzzle,在guzzle中以多部分形式发送json的正确方法是什么。从下面的代码中,应该可以从发布的页面迭代userComment。例如:userComment[0]应给出{'name'=>'Jon',comment'=>'jons comment'}和userComment[0]['name']应打印Jon。但它不起作用 $response = $client->request('POST', $url, [ '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\u encode(userComment[1])
以$data['name']
的方式获得$data['name']
,这看起来不正确。任何帮助,谢谢