快捷搜索 ,解析URL出现乱码问题
快捷搜索搜索任意内容都出现乱码,解决方案如图
代码部分:
part 1:
+ String chartset = getCharset(connection.getContentType());//[M810][bug#41439]HttpURLConnection garbled code,tiansheng 20230717
part 2:
- BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,chartset));//[M810][bug#41439]HttpURLConnection garbled code,tiansheng 202307
part 3:
*//[M810][bug#41439]HttpURLConnection garbled code,tiansheng 20230717 -b
*+ **private** **static** String getCharset(String type) {
\+ String[] typeArray = type.split(";");
\+ String charset = "utf-8";
\+ **for** (int i = 0; i < typeArray.length; i++) {
\+ **if**(typeArray[i].contains("charset")){
\+ String[]tem = typeArray[i].split("=");
\+ charset = tem[1].trim();
\+ }
\+ }
\+ **return** charset;
\+ }
\+ *//[M810][bug#41439]HttpURLConnection garbled code,tiansheng 20230717 -e*