Casa > H > How To Post Data To Firebase With A Curl Command Using Php

How to post data to Firebase with a curl command using PHP

A very simply google search for your exact question lead me to a Stack Overflow post How to post data to firebase using PHP? with a solution.

Solution is:

  1. = '{"id": "6"}'; 
  2.  
  3. = "https://test.firebaseio.com/test_api/types.json"; 
  4. = curl_init(); 
  5. curl_setopt(, CURLOPT_URL, );  
  6. curl_setopt(, CURLOPT_RETURNTRANSFER, true); 
  7. curl_setopt(, CURLOPT_POST, 1); 
  8. curl_setopt(, CURLOPT_POSTFIELDS, ); 
  9. curl_setopt(, CURLOPT_HTTPHEADER, array('Content-Type: text/plain')); 
  10. = curl_exec(); 
  11. if(curl_errno()) 
  12. echo 'Curl error: ' . curl_error(); 
  13. curl_close(); 

Firebase accept json object and you have to post as json object. E você pode usar Content-Type: application/x-www-form-urlencoded ou Content-Type: text/plain

Answer credit goes to User isuru on Stack Overflow.

De Naval Marina

O que é um "sweep de cavalheiros" nos playoffs da NBA? :: Como permitir que lançadores de terceiros lancem aplicativos clonados no MIUI 12 Global