- 服务端发送中文,客户端收到的是乱码。
服务端发送原先逻辑:
HttpURLConnection connection = getConnection();
connection.setDoOutput(true);
JsonObject fcmMessage;
outputStream.writeBytes(fcmMessage.toString());
修正后的逻辑如下(替换转码函数write由发送string,转为发送bytes):
HttpURLConnection connection = getConnection();
connection.setDoOutput(true);
JsonObject fcmMessage;
String outStr = new Gson().toJson(fcmMessage);
outputStream.write(outStr.getBytes("utf-8"));
网友评论