解决java HttpURLConnection接收https请求乱码问题
如果是中文乱码,可以设置读取时使用:
//发送请求报文时
URLConnection out = new OutputStreamWriter(con.getOutputStream(),"UTF-8");
out.write(new String(xmlInfo.getBytes("UTF-8"),"UTF-8"));
out.flush();
//接收响应报文
br = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
如果全乱码,可以尝试设置http请求头:
con.setRequestProperty("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
在报文头中设置编码:
<?xml version="1.0" encoding="UTF-8"?>