无法将索引 35 处的字节 [FC] 从指定代码页转换为 Unicode

Unable to translate bytes [FC] at index 35 from specified code page to Unicode(无法将索引 35 处的字节 [FC] 从指定代码页转换为 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-8tersü的字节为:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)