What is wrong with this CURL call in PHP? [closed]

谁说我不能喝 提交于 2020-01-17 21:34:12

问题


            $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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!