在逻辑应用中转义和删除字符(动态内容)

Escape and remove characters (dynamic content) in a logic app

我一直在尝试从 REST API 获取数据,然后使用逻辑应用程序将其添加到 Azure 中的 Log Analytics。我的问题是,似乎我需要转义 Log Analytics 请求正文中的某些字符,因为我收到 400 错误消息:

{ "Error": "InvalidDataFormat", "Message": null }

我已经检查过 JSON 正文无效。

我的 JSON 请求正文如下所示:

{
"assetid": "TBD Assetid",
"vulnid": "@{items('For_each')?['id']}",
"key": "@{items('For_each_3')?['key']}",
"proof": "@{items('For_each_3')?['proof']}",
"since": "@{items('For_each_3')?['since']}",
"status": "@{items('For_each_3')?['status']}
}

实际请求是这样的:

{
"assetid": "TBD",
"vulnid": "adobe-flash-apsb15-11-cve-2015-3096",
"key": "C:\WINDOWS\system32\Macromed\Flash\",
"proof": "<p><p>Vulnerable OS: Microsoft Windows Server 2012 R2 Datacenter Edition<p></p></p><p>Vulnerable software installed: Adobe Flash 17.0.0.188 (C:\WINDOWS\system32\Macromed\Flash\)</p></p>",
"since": "2021-05-10T11:41:03.483Z",
"status": "vulnerable-version"
}

问题似乎出在反斜杠和段落元素上。

我想转义“key”和“proof”中的反斜杠并删除段落元素。我试图寻找解决方案,但大多数示例都使用静态字符串和替换函数。

有什么想法吗?

您可以使用替换函数删除关键参数的转义字符和段落元素

关键参数:

replace(variables('string2'),'\',''

您也可以使用 replace 作为证明参数,下面是表达式。

证明参数:

replace(replace(replace(variables('string1'),'<p>',''),'</p>',''),'\',''))

这是使用替换函数的示例输出供参考

根据上述要求,我们了解到每次添加到证明参数的 html 标记都可能不同,如果是这种情况,“replace function ()”将无法帮助您。

要删除那些 html 个字符,您可以采用以下两种方法之一:

  1. 使用 Html to text content version 连接器
  2. 按照本文所述使用 Azure functions