这是我post请求的工具类,请求后的返回的结果是乱码。我用String message = newString(userOpenIds.getBytes(), "UTF-8");转了下结果还是有部分字符是乱码。
如果使用String message = newString(userOpenIds.getBytes("ISO-8859-1"), "UTF-8");结果就会变成全是???(问号)
public static String post(String url, String data) {
try {
URL urlObj = new URL(url);
URLConnection connection = urlObj.openConnection();
connection.setDoOutput(true);
OutputStream os = connection.getOutputStream();
os.write(data.getBytes(Charset.forName("utf-8")));
os.close();
InputStream is = connection.getInputStream();
byte[] b = new byte[1024];
int len;
StringBuilder sb = new StringBuilder();
while ((len = is.read(b)) != -1) {
sb.append(new String(b, 0, len));
}
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
首先你要确定一下是哪一步乱码的,传输前乱码、接收时乱码、存入数据库乱码、从数据库读取乱码
是其他名字乱码么?还是表情乱码了
emoji吧