0

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.

2 Answers 2

1

I have managed to solve the issue by changing the cURL php to:

 class trimitereNotificare_app { public function send($email_utilizator, $imagine) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://localhost/sendSinglePush.php" ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, array('title' => 'CityAlert','email' => $email_utilizator,'message' => 'O alertă a fost modificată!','image' => $imagine) ); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data')); $result=curl_exec ($ch); curl_close($ch); } } 
Sign up to request clarification or add additional context in comments.

Comments

0

Also adding if someone is facing similar issues, Postman has added "New Code Generation mode" which can be enabled from settings - if you are on the latest version v.7.19, this is already enabled.

Know more: https://support.getpostman.com/hc/en-us/articles/360036521074-What-is-New-Code-Generation-mode-

Settings> New Code generation mode

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.