0

I am maintaning an API that have some requests made by a front-end app. When I call it from postman, all work well, including its encoding. The response is:

{ "message": "Esse nome de usuário está disponível" }

However, when I make it from browser, I receive:

{"message":"Esse nome de usu\u00e1rio est\u00e1 dispon\u00edvel"}

I already made this tutorial, that creates an middleware forcing the encoding, and on my project I set it like this, unlike the code it sugests:

$request->headers->set('Accept', 'application/json; charset=UTF-8');
$request->headers->set('Charset', 'utf-8');

In postman, I saw that these headers were not setted in the response of the request.

Also, I already tried to set in my controller response:

return response()->json([
                'message' => __('auth.nickname_available'), 
            ], 200, ['Content-Type' => 'application/json;charset=UTF-8', 'Charset' => 'utf-8']);

I followed this tip. But neither worked.

How can I can make this work well?

mhery
  • 2,097
  • 4
  • 26
  • 35

1 Answers1

1

Did you properly try this solution? The following works for me:

return response()->json(
    [
        'Message' => 'Esse nome de usuário está disponível',
    ],
    200,
    ['Content-Type' => 'application/json;charset=UTF-8', 'Charset' => 'utf-8'],
    JSON_UNESCAPED_UNICODE
);

In the response in your question you forgot to add JSON_UNESCAPED_UNICODE

Remul
  • 7,874
  • 1
  • 13
  • 30