我正在通过 Ajax 从 from 提交数据,它需要向端点发出 curl 请求。我没有收到任何错误,但是当我检查端点中的数据时,它不存在。如果我只使用普通的 html 提交表单,那么它就可以工作。所以,我想象的我的 CURL 代码有问题。
<?php
$response = [];
$message = '';
$data = [
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email' => $_POST['email'],
];
$options = [
CURLOPT_URL => 'https://someEndpoint.com?encoding=UTF-8',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => 1
];
$curl = curl_init();
curl_setopt_array($curl, $options);
$results = curl_exec($curl);
curl_close($curl);
$response['success'] = true;
$response['message'] = 'Thank you, your request has been submitted.';
echo json_encode($response);
DIEA