在下面的代码中:
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
构造UTF-8
的setRequestProperty
。HttpsURLConnection
但是,我认为代码确实需要CharSet
从响应中获取。但这似乎是一个先有鸡还是先有蛋的问题。
是否可以检索CharSet
在其响应中实际使用的服务器(而不是将其设置为我 {wished|hoped} 的)?