I got this error:
java.nio.charset.UnsupportedCharsetException: utf8mb4
And I haven't found any solutions yet.
This says that there's no point to solve this problem, as long as, I can't I change the server side.
How can I handle this charset?
I got this error:
java.nio.charset.UnsupportedCharsetException: utf8mb4
And I haven't found any solutions yet.
This says that there's no point to solve this problem, as long as, I can't I change the server side.
How can I handle this charset?
Try to update your database or run:
ALTER DATABASE yourdatabasename CHARACTER SET utf8 COLLATE utf8_unicode_ci
If you can't change nothing on your backend service, try to change your charset configuration on your request like here:
How to suppress Charset being automatically added to Content-Type in okhttp
Here's My solution,
This decodes the response.body() into UTF-8
:
String responseResult = null;
try {
Log.d(TAG, response.body().contentType()+"");
BufferedSource source = response.body().source();
source.request(Long.MAX_VALUE); // Buffer the entire body.
Buffer buffer = source.buffer();
responseResult = buffer.clone().readString(Charset.forName("UTF-8"));
Log.d(TAG, "result: "+responseResult);
}catch(Exception e){
// TODO
}
However, the bigger problem was the URL was incorrect. If it's wrong URL, you can get this error.
For instance,
The URL must be example.com/feed/4
but you sending the request to example.com/feed
.
In my case, after decoding the body, I got 404 ERROR
. And then, realized the URL was wrong. So, I fixed and It worked fine!
The decode might not convert properly, for example, emojis. Then, try it without converting the body. It will work.