I have exported a cURL POST from POSTMAN, where it works just fine, but when i try to run it as php I get the error that the parameters are missing, which is the else from the if(isiset.. about the parameters.
cURL generated by Postman:
<?php class trimitereNotificare_app { public function send($email_utilizator, $imagine) { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "http://localhost/sendSinglePush.php", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => array ('title' => 'CityAlert', 'message' => 'blalvlv', 'email' => "$email_utilizator", 'image' => "$imagine"), CURLOPT_HTTPHEADER => array( "Content-Type: multipart/form-data; boundary=--------------------------748736578315812240456685" ), )); $response = curl_exec($curl); curl_close($curl); echo $response; echo $email_utilizator; echo $imagine; } } The echoes:
{"error":true,"message":"Parameters missing"} [email protected] scopesystems.ro/scopesystems.ro/teste/Pictograme/Strazi si trotuare/ Which are correct as the data that I've passed to the function.
And the .php sendSinglePush:
if($_SERVER['REQUEST_METHOD']=='POST'){ //hecking the required params if(isset($_POST['title']) and isset($_POST['message']) and isset($_POST['email'])){ //creating a new push $push = null; //first check if the push has an image with it if(isset($_POST['image'])){ $push = new Push( $_POST['title'], $_POST['message'], $_POST['image'] ); }else{ //if the push don't have an image give null in place of image $push = new Push( $_POST['title'], $_POST['message'], null ); } //getting the push from push object $mPushNotification = $push->getPush(); //getting the token from database object $devicetoken = $db->getTokenByEmail($_POST['email']); //creating firebase class object $firebase = new Firebase(); //sending push notification and displaying result echo $firebase->send($devicetoken, $mPushNotification); }else{ $response['error']=true; $response['message']='Parameters missing'; } }else{ $response['error']=true; $response['message']='Invalid request'; } As noted in the beginning, the 2nd php says that the parameters are missing, even though in CURLOPT_POSTFIELDS I added the needed ones.
