目前,我需要张贴Activity到DirectLine发送特殊字符的消息,该字符串Menú principal,请注意ú。其他一切正常,但发送特殊字符让我哭了。但是当我发送序列化的活动时,它会显示一个?,以便您可以看到Menú principal != Men? principal哪个将使机器人做出不同的回答。我已经尝试了一些东西,但它似乎不起作用,这是我当前的 POST 功能。 /// <summary> /// Uploads to an URL and gets result /// </summary> /// <typeparam name="T">Type of object you are receiving</typeparam> /// <param name="bearer">Token</param> /// <param name="url">Url</param> /// <param name="serializedJson">Serialized JSON to send</param> /// <returns></returns> public static T uploadString<T>(string bearer, string url, string serializedJson) { string serializedResult = ""; /// Webclient using (var client = new WebClient()) { /// Looks like it goes wrong when uplading UTF8 words string ansistring = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(serializedJson)); try { /// Add headers client.Headers.Add("Content-Type", "application/json"); client.Headers.Add("Authorization", $"Bearer {bearer}"); /// Upload string serializedResult = client.UploadString(url, ansistring); } catch (Exception e) { string a = e.Message; } } /// Get result and return it as an object return JsonConvert.DeserializeObject<T>(serializedResult); }该参数serializedJson是一个Activity使用 Json.NET 序列化的对象,当我尝试发送Menú principal.正如你所看到的text是"text\":\"Menú principal\"。在对话中看到活动日志后,它将显示ú为?.
1 回答
交互式爱情
TA贡献1712条经验 获得超3个赞
该字符不是有效的 ASCII 字符。尝试对您的字符串使用 Unicode 编码:
var stringToSend = Encoding.Unicode.GetString(Encoding.Unicode.GetBytes("Menú principal"));
- 1 回答
- 0 关注
- 133 浏览
添加回答
举报
0/150
提交
取消