问题
$POSTFIELDS = array(
'email' => "fodil@usa.com",
'phone' => "656565465422",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents("php://input") . "&" . $POSTFIELDS);
I can't figure what is wrong with this, it doesn't work, I tried many things but can't make it work...
回答1:
You are passing post fields in a wrong way to the curl. If you are receiving JSON post the use this..
$post = json_decode(file_get_contents('php://input'));
else use normal post array $_POST.
$post = $_POST
then you CURL request will be...
$post['email'] = 'fodil@usa.com';
$post['phone'] = '656565465422';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://example.com");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
来源:https://stackoverflow.com/questions/59104800/what-is-wrong-with-this-curl-call-in-php