Php guzzle指挥所数据
如何通过guzzle服务客户端Php guzzle指挥所数据,php,post,guzzle,Php,Post,Guzzle,如何通过guzzle服务客户端getCommand函数获取post数据 我的json如下所示: "createMessage": { "httpMethod": "POST", "uri": "conversations/{conversation_id}/message", "summary": "conversations by user", "responseType": "class", "respo
getCommand
函数获取post数据
我的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"
}
}
}
然后,我当前将post数据作为通过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'));
它在数据库中创建新记录,但post数据为空,因此'message'
字段保留为空
我试过设置
$client->setPostField('message','testpost message')代码>但似乎不起作用 将内容类型设置为application/x-www-form-urlencoded
似乎已经达到了目的,最初我有:
$command->set('command.headers', array('content-type' => 'application/json'));
但是,Guzzle
中的POST
请求是通过应用程序/x-www-form-urlencoded
内容类型发送的
$command->set('command.headers', array('content-type' => 'application/x-www-form-urlencoded'));
或者,您也可以在json模式中执行此操作,设置内容类型的参数:
"content-type": {
"location": "header",
"default": "application/x-www-form-urlencoded"
}
感谢您成为先锋;)