Я экспортировал cURL
POST
из POSTMAN
, где он работает просто отлично, но когда я пытаюсь запустить его как php
, я получаю сообщение об ошибке, что параметры отсутствуют, а это else
из if(isiset..
о параметрах.
cURL, сгенерированный почтальоном:
<?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;
}
}
Эхо:
{"error":true,"message":"Parameters missing"}
irina@yahoo.com
scopesystems.ro/scopesystems.ro/teste/Pictograme/Strazi si trotuare/
Которые верны как данные, которые я Перешли к функции.
И. php sendSinglePu sh:
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';
}
Как отмечалось в начале, 2 php
говорит, что параметры отсутствуют , хотя в CURLOPT_POSTFIELDS
я добавил нужные.