PHP中的CURL调用有什么问题?

问题描述 投票:0回答:1
            $POSTFIELDS = array(
                    'email' => "[email protected]",
                    'phone' => "656565465422",      
        );  
    curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents("php://input") . "&" . $POSTFIELDS);

我不知道这是怎么回事,它不起作用,我尝试了很多事情,但无法使其起作用...

php php-curl
1个回答
1
投票

您以错误的方式将帖子字段传递给卷发。如果您要接收JSON发布,请使用此。.

$post = json_decode(file_get_contents('php://input'));

否则使用普通的帖子数组$ _POST。

$post = $_POST

然后您的CURL请求将是...

$post['email'] = '[email protected]';
$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);
© www.soinside.com 2019 - 2024. All rights reserved.