为啥php的curl发送请求错误码是0,请求没有发送成功?
private function sendMessage($url, $message) {
//echo $url;
// 初始化cURL会话
$ch = curl_init($url);
// 设置cURL选项
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($message));
// curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 禁用 SSL 证书验证
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 忽略 SSL 证书验证
// 执行请求
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
echo "cURL 错误: " . $error;
echo $response;
echo $httpCode;
// 关闭cURL会话
curl_close($ch);
return [
'response' => $response,
'status_code' => $httpCode
];
}

