我已经从POSTMAN
导出了一个cURL
POST
,在那里它工作得很好,但是当我试图以php
的形式运行它时,我得到了参数丢失的错误,这是从if(isiset..
导出的关于参数的else
。
cURL由 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;
}
}
回声:
{"error":true,"message":"Parameters missing"}
irina@yahoo.com
scopesystems.ro/scopesystems.ro/teste/Pictograme/Strazi si trotuare/
它们与我传递给函数的数据一样正确。
而.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';
}
如开头所述,第二个php
表示缺少参数,尽管我在CURLOPT_POSTFIELDS
中添加了所需的参数。
2条答案
按热度按时间kqlmhetl1#
我已设法解决此问题,方法是将
cURL
php
更改为:v09wglhw2#
此外,如果有人面临类似的问题,波兹曼增加了“新代码生成模式”,可以从设置启用-如果你是在最新版本的v.7.19,这是已经启用。
了解更多信息:https://support.getpostman.com/hc/en-us/articles/360036521074-What-is-New-Code-Generation-mode-