8
我“米试图JSON形式接收POST
数据我冰壶它:PHP解码JSON POST
curl -v --header 'content-type:application/json' -X POST --data '{"content":"test content","friends":[\"38383\",\"38282\",\"38389\"],"newFriends":0,"expires":"5-20-2013","region":"35-28"}' http://testserver.com/wg/create.php?action=post
在PHP端我的代码是:
$data = json_decode(file_get_contents('php://input'));
$content = $data->{'content'};
$friends = $data->{'friends'}; // JSON array of FB IDs
$newFriends = $data->{'newFriends'};
$expires = $data->{'expires'};
$region = $data->{'region'};
但即使当我print_r ($data)
什么都没有回到我这是正确的方式处理POST
没有表格?
你为什么不使用'json_decode($ _ POST)'? – hohner 2013-02-16 20:11:35
@hohner当我尝试时,它给了我错误'json_decode()期望参数1是字符串,数组给出' – Chris 2013-02-16 20:15:43
@hohner因为'$ _POST'被假定为URL编码数据。 – deceze 2013-02-16 20:16:33