简体   繁体   English

C# Azure Function .NET Core 3 字符串编码问题

[英]C# Azure Function .NET Core 3 string Encoding Issue

I have an azure function that is .net core 3 (latest supported) that receives JSON's from Microsoft Dynamics 365 (Common Data Service) when a contact is created or updated.我有一个 azure function 是 .net 核心 3(最新支持),在创建或更新联系人时从 Microsoft Dynamics 365(公共数据服务)接收 JSON。 I am doing no transformation to the data, just grabbing the JSON and placing it in a Service Bus queue.我没有对数据进行任何转换,只是获取 JSON 并将其放入服务总线队列中。 The issue is with international characters.问题在于国际字符。 Example.例子。 the data in Dynamics for first name is Dynamics 中名字的数据是

José何塞

But, as soon as it hits the Azure Function it becomes但是,一旦它到达 Azure Function,它就会变成

José何塞

I removed any UTF-8 encoding that I was doing when reading the body of the HTTP request that this is in and that didn't fix the issue.我删除了我在阅读 HTTP 请求的正文时所做的任何 UTF-8 编码,这并没有解决问题。 I have tried a couple of things and can't figure out what is happening to the data even before I try to read it.我已经尝试了几件事,甚至在尝试读取数据之前也无法弄清楚数据发生了什么。

Here is what I have tried.这是我试过的。 I need to read the data as it is in Dynamics and convert it to UTF-8 as the system I am sending the data too is using UTF-8.我需要读取 Dynamics 中的数据并将其转换为 UTF-8,因为我发送数据的系统也在使用 UTF-8。

Original:原来的:

string requestBody = await CommonFactory.StreamReader(req.Body).ReadToEndAsync();

I have tried the following:我尝试了以下方法:

        string requestBody = await req.Content.ReadAsStringAsync();

        dynamic data = await req.Content.ReadAsAsync<object>();

I have also tried to see the headers that are sent and content-type does not include the charset value.我还尝试查看发送的标头,内容类型不包括字符集值。 Just has刚刚有

application/json应用程序/json

I am hoping that someone else has run across issues with string encoding with .NET core and can help point me in the right direction.我希望其他人遇到过 .NET 核心的字符串编码问题,可以帮助我指明正确的方向。 Right now, I am trying to switch to memory stream to see if that helps at all.现在,我正在尝试切换到 memory stream 看看是否有帮助。

After some deeper testing, I think there is something in the Function framework.经过一些更深入的测试,我认为 Function 框架中有一些东西。 I moved from using a Webhook in plugin registration tool to a service endpoint.我从在插件注册工具中使用 Webhook 转移到服务端点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM