Asp.net core ASP.NET核心REST正文包含Dto对象前后的字符

Asp.net core ASP.NET核心REST正文包含Dto对象前后的字符,asp.net-core,asp.net-web-api,Asp.net Core,Asp.net Web Api,此问题可通过以下步骤重现 开放式Visual Studio 2019 创建新项目 ASP.NET核心web应用程序 使用角度模板 在控制器中创建一个子目录,并将其称为WebApi 添加新控制器 选择Api控制器读/写操作 将控制器命名为TestController 将以下函数添加到TestController [HttpGet] [Route("TList")] [ProducesResponseType(StatusCodes.Status200OK)] [Produces("applicat

此问题可通过以下步骤重现

  • 开放式Visual Studio 2019
  • 创建新项目
  • ASP.NET核心web应用程序
  • 使用角度模板
  • 在控制器中创建一个子目录,并将其称为WebApi
  • 添加新控制器
  • 选择Api控制器读/写操作
  • 将控制器命名为TestController
  • 将以下函数添加到TestController

    [HttpGet]
    [Route("TList")]
    [ProducesResponseType(StatusCodes.Status200OK)]
    [Produces("application/json")]
    public ActionResult<TestDto> TList()
    {
        TestDto result = new TestDto();
        result.Title = "Title";
        result.DataList = new List<TestItem>();
        result.DataList.Add(new TestItem() { Title = "Test" });
    
    return Ok(result);
    }
    

    如何去掉2f和0?

    这些字符是Fiddler特有的。他们不能在Chrome或Postman中看到。这些字符不会影响反序列化,因为以下代码使用包含这些字符的Rest响应

    this.http.get('https://localhost:44383/api/test/TList').subscribe((data : TestDto) => {
      this.myData = data;
       this.title = data.title;
    });
    

    其他的东西正在破坏响应体。这里没有足够的东西来诊断。一般来说,这样的东西是一个编码问题,但它是以UTF8的形式发送的,所以这应该不是问题。@Chris Pratt您还需要什么信息?请求的方式/内容?我正在使用Fiddler在headerReferer中处理以下内容:用户代理:Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,像Gecko)Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362 Accept:application/json接受语言:en-US,en;q=0.8,de-CH;q=0.5,de;q=0.3接受编码:gzip,deflate,br主机:localhost:44317连接:保持活动
    HTTP/1.1 200 OK
    Transfer-Encoding: chunked
    Content-Type: application/json; charset=utf-8
    Server: Microsoft-IIS/10.0
    X-Powered-By: ASP.NET
    Date: Wed, 18 Dec 2019 07:38:29 GMT
    
    2f
    {"title":"Title","dataList":[{"title":"Test"}]}
    0
    
    this.http.get('https://localhost:44383/api/test/TList').subscribe((data : TestDto) => {
      this.myData = data;
       this.title = data.title;
    });