public static void send(String urlPath, String content) throws JSONException { try { URL url = new URL(urlPath); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestMethod(“POST”); connection.setUseCaches(false); connection.setInstanceFollowRedirects(true); connection.setRequestProperty(“Content-Type”, “application/json”); connection.setRequestProperty(“Authorization”, “”); connection.connect(); DataOutputStream out = new DataOutputStream(connection.getOutputStream()); JSONObject json = new JSONObject(); json.put(“to”, “erUretmvVrM:APA91bEWrUIsl1KawvionLeu3YkBqrH2cYKoeAy7Pc16J7xZcNVwvzQKbPYc14K90YBcbysxkkFzr7HUKX7vj0T9XrDbD3uFsI7v4J3LZmtwiGe2PsK49JcnLyJMiYmFz3wnS9J6Ycot”); JSONObject info = new JSONObject(); info.put(“title”, “Notificatoin Title”); //通知标题 info.put(“body”, “Hello Test notification”); // Notification body json.put(“notification”, info); out.writeBytes(json.toString()); out.flush(); out.close(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String lines; StringBuffer sb = new StringBuffer(“”); while ((lines = reader.readLine()) != null) { lines = new String(lines.getBytes(), “utf-8”); sb.append(lines); } System.out.println(sb); reader.close(); // 断开连接 connection.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
}