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

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

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

调用工作正常,我的 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

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.