I am sending a request to an API in ASP.NET from Android, I am using Spring Framework to make requests, the problem is that when sending a JSON that contains accented characters the server returns an exception with the following message:
{"exception":"Object reference not set to an instance of an object."}
The problem only occurs with the accents, and from the Android app, I sent an identical request (with accents) using Postman, and the server accepts it without problems.
This is the code I'm using in Java:
RestTemplate rest = new RestTemplate();
JSONObject request = new JSONObject()
.put("Title", "título")
.put("Content", "contenido del mensaje");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<>(request.toString(), headers);
ResponseEntity<String> response = rest.exchange("http://elsitio.com/message/post?authToken={authToken}", HttpMethod.POST, entity, String.class, Session.getToken());
I have already tried changing the server language and it does not work.