question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

resttemplate not send body unicode chars

See original GitHub issue

Affects: Spring Boot 2.1.13


i have tryed to send same body with: curl, postman and rest template with java.

with rest template chars not show correctly

private CompletableFuture<String> sendToFCM(String entity, String firebaseServerKey) {
        RestTemplate restTemplate = new RestTemplate();

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.set("Authorization", "key=" + firebaseServerKey);
        HttpEntity<String> request = new HttpEntity<>(entity, headers);
        restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));

        String firebaseResponse = restTemplate.postForObject(FIREBASE_API_URL, request, String.class);
        return CompletableFuture.completedFuture(firebaseResponse);
    }

I attach

curl -X POST --header “Authorization: key=KEY IS HIDDEN” --Header “Content-Type: application/json;charset=ISO-8859-1” https://fcm.googleapis.com/fcm/send -d ‘{“to”:“/topics/VgtARwhilq”,“notification”:{“body”:“\uD83D\uDD25”,“content_available”:true,“priority”:“high”,“title”:“\uD83D\uDD25”},“data”:{“click_action”:“FLUTTER_NOTIFICATION_CLICK”,“body”:“\uD83D\uDD25”,“title”:“\uD83D\uDD25”,“content_available”:true,“priority”:“high”}}’

curl or postman result is right call with curl

Can you help me?

Best Regards

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rstoyanchevcommented, Apr 15, 2020

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

0reactions
sante85commented, Apr 11, 2020

@encircled in this mode? RestTemplate restTemplate = new RestTemplate();

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.set("Authorization", "key=" + firebaseServerKey);
    HttpEntity<String> request = new HttpEntity<>(entity, headers);
    restTemplate.getMessageConverters().add(0, new MappingJackson2HttpMessageConverter());

    String firebaseResponse = restTemplate.postForObject(FIREBASE_API_URL, request, String.class);
    return CompletableFuture.completedFuture(firebaseResponse);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Java Spring resttemplate character encoding - Stack Overflow
I have solved this problem. I need to POST a string object in request body with UTF-8.
Read more >
Using URL encoding to handle special characters in a ...
In this article, we will walk through a scenario where exceptions are thrown if such a URI with special character is not handled...
Read more >
REST API Unicode characters not working
I've been able to reproduce this in a test environment using Workbench. It appears that Salesforce by default interprets text in the body...
Read more >
Uploading a file with a filename with Spring RestTemplate
File upload is sent via Multipart Form Data. This format allows to embed multiple independent information in the body of an HTTP Post...
Read more >
Spring Boot REST Template URI Encoding - DZone
If using special characters, you might want to use the URL encoder on specific charsets. In this case, we're using UTF_8. This is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found