title: HTTP Post message for firebase in Java
body: <p>I would like to send a notification from my Java program to Firebase. But I don't know how to do that.</p>
  
  <p>In order to send a notification using curl:</p>
  
  <pre><code># api_key=YOUR_SERVER_KEY
  
  # curl --header "Authorization: key=$api_key" \
     --header Content-Type:"application/json" \
     https://fcm.googleapis.com/fcm/send \
     -d "{\"registration_ids\":[\"ABC\"]}"
  </code></pre>
  
  <p>I want the equivalent of that in Java. I tried the following but it is not correct</p>
  
  <pre><code>String rawData =  "{\"registration_ids\":[\"ABC\"]}";
  String encodedData = URLEncoder.encode( rawData, "UTF-8" ); 
  
  URL u = new URL("https://fcm.googleapis.com/fcm/send");
  HttpURLConnection conn = (HttpURLConnection) u.openConnection();
  conn.setDoOutput(true);
  conn.setRequestMethod("POST");
  conn.setRequestProperty("Authorization", "key="+api_key);
  conn.setRequestProperty("Content-Type", "application/json");
  OutputStream os = conn.getOutputStream();
  os.write(encodedData.getBytes());
  </code></pre>