In the code below:
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestProperty("charset", "utf-8");
InputStream input = connection.getInputStream();
InputStreamReader reader = new InputStreamReader(input, "utf-8");
BufferedReader buffer = new BufferedReader(reader);
...
An InputStreamReader
is constructed with UTF-8
because of setRequestProperty
of HttpsURLConnection
. However, I think the code really needs to get the CharSet
from the response. But it seems like a chicken-and-the-egg problem.
Is it possible to retrieve the CharSet
the server actually used in its response (instead of setting it to what I {wished|hoped} for)?