JSON 逻辑应用程序发送消息错误

Logic App Send Message error with JSON

我正在使用逻辑应用向 Azure 上的服务总线发送消息。逻辑应用以针对触发器的 HTTP 请求开始,该请求在正文中包含 JSON 负载。请求的 'Body' 设置为发送消息操作的内容。由于在发布时负载是 JSON,我将 Content-Type 设置为 application/json。这会在“发送消息”操作中产生错误;

{"code":"InvalidTemplate","message":"Unable to process template language expressions in action 'Send_message.' inputs at line '1' and column '1221': 'The template language function 'encodeBase64' expects its parameter to be a string. The provided value is of type 'Object'. Please see https://aka.ms/logicexpressions#encodeBase64 for usage details.'."}

所以尝试将 Content-Type 更改为 text/plain 并且有效?这是一个错误还是应该在发送消息操作中使用它之前以某种方式将 JSON 转换为文本值?

向服务总线发送消息需要对消息内容进行 base64 编码。由于您的内容是 JSON,因此您需要在编码之前对其进行显式字符串化,即使用 @encodeBase64(string(jsonContent))

将内容类型更改为 text/plain 具有相同的效果,因为在这种情况下,内容被视为以字符串开头。