Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php guzzle指挥所数据_Php_Post_Guzzle - Fatal编程技术网

Php 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

如何通过guzzle服务客户端
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"
 }

感谢您成为先锋;)