https://toitlang.org/ logo
It was my error. Need to use --uri= instead of --h...
# general
m
It was my error. Need to use --uri= instead of --host= . Here is a sample that working fine:
Copy code
import certificate-roots
import http
import net
import encoding.json

// Firebase Realtime Database URL
URI := "https://weather-84204-default-rtdb.firebaseio.com/temperature.json"
OK  := 200

main:

  certificate-roots.install-common-trusted-roots

  // Establish network connection
  network := net.open
  client := http.Client network

  meteo_data := {
    "Location": "Boston",
    "Temperature": "33"
  }

  // Encode data to JSON
  json_object := json.encode meteo_data

  try:

    e := catch --trace=false :
    // Send POST request
      response := client.post --uri=URI json_object
      data := json.decode-stream response.body

    // Check response
      if response.status_code == OK :
        print "Record successfully created: $data"
      else:
        print "Error: $(response.status_code) - $data"

    if e :
      print "Exception->$e.stringify"

  finally:
    client.close
    network.close
Thanks for your help.