altv-issues icon indicating copy to clipboard operation
altv-issues copied to clipboard

C# clientside HttpClient does not favor Content-Encoding

Open c0nnex opened this issue 1 year ago • 0 comments

Description of the problem

When requesting (GET) data from a server that is encoded in UTF-8 (which is Json default) the resulting HttpResponse.Body-string in the c# Client is ISO-8859-1 encoded (breaking all special characters) and not UTF-8 as desired. Same applies for UTF-8 encoded html files

Reproduction steps

Client:

         Task.Run(async () =>
            {
                var hClient = Alt.CreateHttpClient();
                var hResponse = await hClient.Get("http://127.0.0.1:1234/GetSomeJsonData");
                /* Server returns (according to chrome debug):
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Content-Length: 2764
Content-Type: application/json; charset=UTF-8
Expires: 0
Server: Microsoft-HTTPAPI/2.0
Access-Control-Allow-Origin: *
Date: Mon, 16 Sep 2024 22:24:47 GMT

{"ItemId": 233,"Name": "Schlüsselbund"}
                
                 (Data truncated for showcase)*/
                Alt.Log(hResponse.Body);
/* Logfile Shows
{"ItemId": 233,"Name": "Schlüsselbund"}
*/
                hClient.Destroy();
            });

Expected behaviour

HttpResponse.Body using correct encoding

Additional context

Workaround:

Encoding.UTF8.GetString(Encoding.GetEncoding("ISO-8859-1").GetBytes(httpResponse.Body))

will correct the encoding

Operating system

Windows

Version

alt:V build #16.2.6, branch release

Crashdump ID

No response

Confirmation of issue's presence

  • [X] By submitting this ticket, I affirm that I have verified the presence of this issue on the latest RC (Release Candidate) version available at the time of writing this ticket.

c0nnex avatar Sep 16 '24 22:09 c0nnex