I am sending a UnityWebRequest to my Java Spring Server from my application in Unity. If I send the word "house", then "houseÔÇï" arrives there. However, the error does not happen when I send the request from Postman, for example.
The creation of the Request in Unity:
private UnityWebRequest CreateRegistrationRequest()
{
var webRequest = UnityWebRequest.Post(REGISTRATION_URL, string.Empty);
webRequest.SetRequestHeader("Content-Type", "application/json");
webRequest.SetRequestHeader("charset", "utf-8");
var req = new RegistrationRequest();
req.email = usernameField.text.Trim();
req.password = passwordField.text.Trim();
string jsonData = JsonUtility.ToJson(req);
webRequest.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(jsonData));
return webRequest;
}
My application.yml:
server:
error:
include-message: always
include-binding-errors: always
spring:
datasource:
password: password
url: jdbc:postgresql://localhost:5432/registration?charSet=UTF8
username:
jpa:
hibernate:
ddl-auto: create-drop
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
format_sql: true
connection:
charSet: UTF-8
show-sql: true
RegistrationRequest:
using System;
[Serializable]
public class RegistrationRequest
{
public string email;
public string password;
}
As mentioned, the error does not appear when I send the request from Postman.
I assume that the issue has something to do with the Byte Order Mark (BOM), which seems to be optional in UFT-8 and is not supported by every platform. Therefore I tried to disable the BOM:
webRequest.uploadHandler = new UploadHandlerRaw(new UTF8Encoding(false).GetBytes(jsonData));
It did not work. Same issue. I even tried to change the encoding to utf-32, but same issue as well.