【发布时间】:2018-06-01 10:40:41
【问题描述】:
我正在尝试使用 AWS SDK for PHP 中的 postContent 将我的网页连接到我的 Lex 机器人。
我设置了凭据和参数,然后尝试 postContent。以下是相关代码:
$credentials = new \Aws\Credentials\Credentials('XXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXXXX');
$args = array(
'region' => 'us-east-1',
'version' => 'latest',
'debug' => true,
'credentials' => $credentials
);
$lex_client = new Aws\LexRuntimeService\LexRuntimeServiceClient($args);
$lex_response = $lex_client->postContent([
'accept' => 'text/plain; charset=utf-8',
'botAlias' => 'XXXX',
'botName' => 'XXXX',
'contentType' => 'text/plain; charset=utf-8',
'inputStream' => $userInput,
'requestAttributes' => "{}",
'sessionAttributes' => "{}",
'userId' => 'XXXXXXXXXXXX',
]);
此错误:
'在“https://runtime.lex.us-east-1.amazonaws.com/bot/XXXX/alias/XXXX/user/XXXXXXXXXX/content”上执行“PostContent”时出错;
AWS HTTP 错误:客户端错误:
POST https://runtime.lex.us-east-1.amazonaws.com/bot/XXXX/alias/XXXX/user/XXXXXXXXXX/content导致400 Bad Request响应: {"message":"无效请求:无法解码会话属性。会话属性应该是字符串到字符串的 Base64 编码 json 映射"}' (length=142)
我尝试在 sessionAttributes 中使用各种 JSON 字符串、JSON 编码字符串和 Base64 编码字符串,但我仍然遇到同样的错误。
【问题讨论】:
-
您是否尝试将 Content-type 设置为 application/json ?
-
@ParrettApps 感谢您的建议,值得一试,但是:Error="Unsupported content type application/json"
标签: php amazon-lex