Unable to translate bytes [FC] at index 35 from specified code page to Unicode(无法将索引 35 处的字节 [FC] 从指定代码页转换为 Unicode)
问题描述
我正在尝试将这样的对象发送到我的 REST API(使用 asp net core 构建)
I'm trying to send an object like this to my REST API(built with asp net core)
{
"firstName":"tersü",
"lastName":"asda"
}
这就是 SoapUI 中标题的外观:
And this is how the headers form SoapUI look:
Accept-Encoding: gzip,deflate
Content-Type: application/json:charset=UTF-16
Host: localhost:4004
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
但是,我的 actionContext.ModelState 始终无效,因为它不能与元音变音一起使用.例外情况如下:
However, my actionContext.ModelState is always invalid because it can not work with the umlaute. The exception is the following:
无法将索引 35 处的字节 [FC] 从指定代码页转换为统一码
Unable to translate bytes [FC] at index 35 from specified code page to Unicode
如果有任何帮助,方法签名如下所示:
If it's any help, the method signature looks like this:
[ValidateUserData]
public async Task<IActionResult> Update(string userId, [FromBody] UpdateUserRequest updateRequest)
基本上代码从不重复
if (!actionContext.ModelState.IsValid)
{
actionContext.Result = new BadRequestObjectResult(actionContext.ModelState);
}
在 [ValidateUserData] 属性中
我在这里错过了什么?
推荐答案
你正在发送用 utf-16 编码的字符串,但是告诉(在 Content-Type标头的字符集)它是 utf-8.
You are sending your string encoded in utf-16, but telling (in the Content-Type header's charset) it is utf-8.
utf-8中tersü的字节为:
74,65,72,73,C3,BC
但是 tersü(在 utf-16 中)包含字节(注意那里的 FC):
However tersü (in utf-16) contains the bytes (notice the FC there):
74,0,65,0,72,0,73,0,FC,0
(检查它in this fiddle)
所以它只是无法理解它.因此,要么在发送之前将您的字符串转换为客户端中的 utf-8,要么将 Content-Type 字符集设置为 utf-16.
So it just can't understand it. So either convert your string to utf-8 in your client before sending it, or set the Content-Type charset to utf-16 .
这篇关于无法将索引 35 处的字节 [FC] 从指定代码页转换为 Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法将索引 35 处的字节 [FC] 从指定代码页转换为 Unicode
基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
