-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request cannot send utf_8 charset when the body is not null #4
Comments
I am having this same type of issue, and if I put apache httpclient on DEBUG I can see it returns "Unrecognized UTF8 Byte at position 254". This seems to be because when creating Entities, the client class doesn't specify a Charset or Character Encoding (https://github.com/sendgrid/java-http-client/blob/master/src/main/java/com/sendgrid/Client.java#L210), so it defaults to ContentType.TEXT_PLAIN wich has a Charset of "ISO-8859-1". The API seems to require "UTF-8", so if I change the Client class to specify that for all StringEntities it works:
|
@toran414 would you like put in a pull request? If so, could you please sing our CLA: https://github.com/sendgrid/java-http-client/blob/master/CONTRIBUTING.md#cla |
I was debugging and noticed the same problem with Cyrillic symbols .. just need to replace @toran414 could you please create PR Thank you |
For people looking for a quick fix, you can remove all invalid utf-8 chars from your email string. String email_content = "<html><body>content here</body></html>";
try {
email_content = new String(email_content.getBytes("US-ASCII"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} |
@goldbattle I want to use |
For my application it was not needed, it doesn't fix the root cause. Just
|
This issue should be fixed in version 2.3.1 (just released) Thanks again @DanailMinchev |
Issue Summary
I try to use the sendgrid template and I set the personalization, but one value like this : "Irène" this is word using utf-8 charset. I have set headers
requestHeaders.put("Content-Type", "application/json; charset=utf-8");
request.headers = requestHeaders;
But the return is : org.apache.http.client.HttpResponseException: Unsupported Media Type
I use sendgrid 2.2.2 is ok.
So I check the client.java and find you set the
content_type : "application/json" when the body is not null.
Steps to Reproduce
Could you check the headers if there exists the content_type, don't set the content-type automatically?
or you tell me how to sovle this problem ?
Thank you.
Technical details:
The text was updated successfully, but these errors were encountered: