java,HttpURLConnection输出汉字乱码,怎么解决啊?

2024-12-01 10:44:50
推荐回答(2个)
回答1:

conn = (HttpURLConnection) mUrl.openConnection();
conn.setRequestMethod("GET");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Content-type","application/x-www-form-urlencoded;charset=UTF-8");  //解决乱码问题
conn.connect();  //连接远程服务器

重点这一句:application/x-www-form-urlencoded;charset=UTF-8

回答2:

new InputStreamReader(is));

改成
new InputStreamReader(is, "UTF-8"));