问题描述
我正在尝试将这样的对象发送到我的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)