Skip to content

Instantly share code, notes, and snippets.

Created Mar 4, 2019
What would you like to do?
Ruby script to send POST HTTPS request sample
# source:
# FCM ref:
# How to run in terminal: ruby test_fcm.rb
require 'net/https'
require 'uri'
require 'json'
uri = URI.parse('')
device_token = 'FCM_device_token'
header = {
'Authorization': 'key=Legacy_server_key',
'Content-Type': 'application/json'
form_data = {
to: device_token,
data: {
alert: 'You received a notification!',
badge: 1,
body: 'Some body'
# Create the HTTP objects
http =, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request =, header)
request.body = form_data.to_json
# Send the request
response = http.request(request)
puts JSON.pretty_generate(JSON.parse(response.body))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment