我有一个通过curl 将请求发送到end-point.php 的php 代码。在 end-point.php 中,我尝试显示传输数据的值,但没有显示任何内容。这是我的代码:
// Prepare subscriber data
$data = array(
$name = "John",
);
// Set cURL options
$url = "https://www.example.com/end-point.php";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: multipart/form-data'
));
// Execute cURL request
$response = curl_exec($ch);
$curl_error = curl_error($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Check if the request was successful
if ($http_code >= 200 && $http_code < 300) {
echo $response;
} else {
// Output error message
echo "Error";
}
这是 end-point.php 文件的代码:
echo $_POST['name'];
我不知道这个语法是否有效,但是
$data
有错误应该是:
// Prepare subscriber data
$data = array(
name => "John",
);