asp.net核心2 webapi无效字符

时间:2017-12-06 12:36:24

标签: character-encoding .net-core asp.net-core-2.0

我正在使用Asp.net Core 2.0 WebApi项目,并尝试访问Get()方法并为其生成有目的的错误。 我将来自Http错误的信息发送给消费者客户端:

        <form method="get" action="cftv_captar.asp">
            <div class="artigo cftv_representante cftv_representante_form">

                    <h1 style="grid-area: h1">Seja um de nossos representantes:</h1>
                    <p style="grid-area: p"><i style="color:#a0c402;">Todos os campos abaixo são obrigatórios</i></p>
                    <label style="grid-area: nome1">Nome completo:</label>
                    <input style="grid-area: nome2" type="text" name="txtNome" id="txtNome" placeholder="Nome Sobrenome" maxlength="100" required />
                    <label style="grid-area: email1">E-mail:</label>
                    <input style="grid-area: email2" type="text" name="txtEmail" id="txtEmail" placeholder="nome@dominio.com.br" maxlength="80" required />
                    <label style="grid-area: cpf1">CPF:</label>
                    <input style="grid-area: cpf2" type="text" name="txtCPF" id="txtCPF" placeholder="___.___.___-__" maxlength="14" required />
                    <label style="grid-area: telefone1">Telefone celular:</label>
                    <input style="grid-area: telefone2" type="text" name="txtCelular" id="txtCelular" placeholder="(__)_____-____" maxlength="15" required />
                    <input style="grid-area: botao" class="cftv_btn_envia_representante" type="submit" value="Enviar">  

            </div>
        </form>

当客户端收到ReasonPhrase时,它具有无效字符,在其中加以重音:

  

“N?o foi encontrado”

正确的是:

  

“Nãofoiencontrado”

我想我会有如何为UTF-8配置编码,但我无法弄清楚如何做到这一点。你能救我吗?

1 个答案:

答案 0 :(得分:0)

你可以用 HttpContext.Response.ContentEncoding = Encoding.GetEncoding(“utf-8”)

但据我所知,默认情况下是utf-8,这也是我所知道的,我可能会非常错误