如何通过 guzzle 服务客户端getCommand
功能获取发布数据?
我的 json 如下所示:
"createMessage": {
"httpMethod": "POST",
"uri": "conversations/{conversation_id}/message",
"summary": "conversations by user",
"responseType": "class",
"responseClass": "\\Conversations\\Message",
"parameters": {
"conversation_id": {
"location": "uri",
"description": "conversation id",
"type": "integer"
},
"message": {
"location": "postField",
"sentAs": "message",
"type": "string"
}
}
}
然后我目前将我的帖子数据作为通过 getCommand 传递的数组的一部分:
$client = new \Guzzle\Service\Client();
$client->setDescription(\Guzzle\Service\Description\ServiceDescription::factory(__DIR__ . '/client.json'));
$command = $client->getCommand('createMessage', array('conversation_id' => 6, 'message' => 'test post message'));
它在数据库中创建新记录,但发布数据为空,因此该'message'
字段为空。
我试过设置$client->setPostField('message', 'test post message');
,但似乎不起作用。