Dynamics365 CRM - 将 Azure 函数调用为 Webhook - 文本编码挑战

问题描述 投票:0回答:1

我有一个 Azure 函数(C#、.NET 8),当我们的自定义实体的名称在 Dynamics CRM 中发生更改时,该函数会通过 Webhook 从基于云的 MS Dynamics365 CRM 系统调用。

调用工作正常,我的 Azure 函数被调用,并且发出

POST
请求。但是,我无法读出
POST
正文的内容。

由于我位于主要讲德语的地区,因此我们的许多名字都会包含变音符号 -

ä ö ü Ä Ö Ü
- 当调用 webhook 时,这些变音符号会以某种方式被“损坏”。

这是我的 Azure 函数(简化):

public class MyFunction
{
    [Function("MyFunction")]
    public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestData req)
    {
        string postJson = await new StreamReader(req.Body, Encoding.UTF8).ReadToEndAsync();
 
        // handle the message that the entity has changed
    }
}   

我得到的 JSON 中的某个位置是实体的新名称 - 不幸的是,变音符号没有正确表示。

当我在 Dynamics 中将一个实体的名称更改为

Präsident 2024
时,我在 JSON 帖子正文中得到的是:

Präsident 2024

我尝试了任何我能想到的有意义的编码 -

Latin1
ASCII
UTF-32
Unicode
- 但没有任何效果 - 它们都返回一个“乱码”的新名称。

为什么会出现这种情况?我需要采取什么编码或什么方法来获取我的 Dynamics 实体的实际,正确的新名称?

更新

这就是我在 MS Dynamics 中的输入:

enter image description here

存储到 DataVerse 中的内容 - 对我来说仍然看起来很好:

enter image description here

更新#2

对于@PanagiotisKanavos

使用

string postJson = await req.ReadAsStringAsync();

没有改变任何事情 - 仍然是与德语变音符号非常相同的“损坏”(或双重编码)......

这是标题集合(稍微“调整”以保护无辜者 - 似乎没有任何迹象表明与文本编码有关)...

Connection: Keep-Alive
Content-Length: 4667
Content-Type: application/json
Expect: 100-continue
Host: myfunction-dev.azurewebsites.net
Max-Forwards: 9
x-functions-key: HLruyEwOS2wn_al_4a8bsqM25pMGR1FpP7vZh9V6t5G6AzFuEXhFYA==
x-ms-dynamics-organization: ********.crm4.dynamics.com
x-ms-dynamics-entity-name: ambcust_tag
x-ms-dynamics-request-name: Update
x-ms-correlation-request-id: c51275a3-985d-4b5b-adb2-a375db9ab3d3
x-arr-log-id: fea83f29-a979-4e37-a6c5-0cd0f6763ebe
client-ip: 20.50.69.12:61953
disguised-host: myfunction-dev.azurewebsites.net
x-site-deployment-id: myfunction-dev
was-default-hostname: myfunction-dev.azurewebsites.net
x-forwarded-proto: https
x-appservice-proto: https
x-arr-ssl: 2048|256|CN=Microsoft Azure TLS Issuing CA 05, O=Microsoft Corporation, C=US|CN=*.azurewebsites.net, O=Microsoft Corporation, L=Redmond, S=WA, C=US
x-forwarded-tlsversion: 1.3
x-forwarded-for: 20.50.69.12:61953, 20.50.69.12
x-original-url: /api/HandleUpdate
x-waws-unencoded-url: /api/HandleUpdate
x-ms-coldstart: 1
c# azure-functions webhooks dynamics-365
1个回答
0
投票

感谢@madreflection。

正如我在评论中所说,问题与功能无关。输入在进入函数体之前已更改。

我的代码;

       [Function("Function1")]
       public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req)
       {
           _logger.LogInformation("C# HTTP trigger function processed a request.");
           string postJson = await new StreamReader(req.Body, Encoding.UTF8).ReadToEndAsync();

           string decoded = Encoding.UTF8.GetString(Encoding.Default.GetBytes(postJson));

           return new OkObjectResult($"{decoded}");

输入:

Präsident

OUTPUT

Präsident

© www.soinside.com 2019 - 2024. All rights reserved.