gpt4 book ai didi

php - Guzzle 指挥所数据

转载 作者:行者123 更新时间:2023-12-04 04:36:10 31 4
gpt4 key购买 nike

我如何通过 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');但似乎不起作用。

最佳答案

将内容类型设置为 application/x-www-form-urlencoded似乎已经成功了,最初我有:

$command->set('command.headers', array('content-type' => 'application/json'));

然而 POST请求在 Guzzle发送时带有 application/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"
}

关于php - Guzzle 指挥所数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19713184/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com