Send Push Notification to User Devices - Java

Source Code Option 1: OkHttpClient

  

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "api_key=YOUR-API-KEY&user_id=YOUR-CUSTOM-USER-ID&msg_title=test%20message&destination_url=https%3A%2F%2Fpushnotificationapi.com");
Request request = new Request.Builder()
  .url("https://send.pushnotificationapi.com/v1/push/send_by_userid")
  .post(body)
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();

 

Source Code Option 2: Unirest

  

HttpResponse<String> response = Unirest.post("https://send.pushnotificationapi.com/v1/push/send_by_userid")
  .header("content-type", "application/x-www-form-urlencoded")
  .header("cache-control", "no-cache")
  .body("api_key=YOUR-API-KEY&user_id=YOUR-CUSTOM-USER-ID&msg_title=test%20message&destination_url=https%3A%2F%2Fpushnotificationapi.com")
  .asString();