【问题标题】:ASP.NET Core Web API HttpPost with charset1252带有 charset1252 的 ASP.NET Core Web API HttpPost
【发布时间】:2019-05-15 22:03:40
【问题描述】:

我正在尝试将我的 WebAPI 配置为接受 UTF-8 以外的字符集。我已将编码添加到 JsonInputFormatter 中,如下所示:

 Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

        var enc1252 = Encoding.GetEncoding(1252);

        services.AddMvc(options => options.InputFormatters.OfType<JsonInputFormatter>().First().SupportedEncodings.Add(
            enc1252));

我指定以下HttpHeader:

Content-Type: application/json;charset=windows-1252

但是,我只能返回 415 Unsupported Media Type。 如果我将标头更新为 utf-8 或 unicode,那么这将起作用。我做错了什么?

【问题讨论】:

    标签: c# asp.net asp.net-web-api .net-core


    【解决方案1】:

    问题是

    options.InputFormatters.OfType().First

    正在使用 JsonPatchInputFormatter。更新为将编码添加到 JsonInputFormatter 和 JsonInputPatchFormatter 中,这解决了问题

    【讨论】:

    • 如果这解决了你的问题,那么你可以接受你自己的答案作为更正的答案:)
    猜你喜欢
    • 2022-10-13
    • 2018-12-30
    • 2021-01-27
    • 2019-05-15
    • 2018-04-12
    • 2021-11-17
    • 2020-04-16
    • 2021-08-27
    • 1970-01-01
    相关资源
    最近更新 更多