Invalid leading characters in response

I’m fairly new to slim framework, but not to Web API at all. Nevertheless, in all my responses (no matter of the HTTP verb or the response code), there are (invisible) leading characters in front of the json respons body. I have no idea where they are coming from, but the prevent my client application from deserializing the object.

If I copy the response body to Notepad++ and switch the encoding from UTF-8 to ANSI, the response looks like:
"{“token”:“eyJ0eXAiOiJKV1QiLCJhbGciOi…}”

I’m using HttpBasicAuthentication to get the token and JwtAuthentication afterwards. But since all requests are returning those characters, I don’t think this is related to the issue.

Any hint from anybody is highly appreciated! Thanks a lot!!
Dave

Three words for you:

Byte Order Mark (BOM)

That’s the representation for the UTF-8 BOM in ISO-8859-1. You have to tell your editor to not use BOMs or use a different editor to strip them out.

Dear @odan

Thanks a lot! Makes absolutely sense! But why is RestSharp client or Newtonsoft JSON both failing to deserialize the response? This should - also with BOM - not happen, right? I can understand it now, but the behavior of both libraries does not yet make sense to me… :wink:

Thanks for your help!
Dave

I finally understand it… I once created a file on the server with Filezilla. This file was created in UTF-8 with BOM. The leading BOM (in front of the <?php) was therefore always sent to the client - no matter what route I used.

This article helped me to find the source of the wrong behavior and made me understand, what happened! Thanks a lot!