且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Curl_exec在PHP中返回null

更新时间:2023-02-24 14:39:25

这是尝试使用 CURLOPT_RETURNTRANSFER (用于返回输出)和 curl_errno()的方法以跟踪错误:

This is how you can try with CURLOPT_RETURNTRANSFER which is used to return the output and curl_errno() to track the errors :

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://example.com/my_url.php" ); 
curl_setopt($ch, CURLOPT_POST, 1 ); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$postResult = curl_exec($ch); 

if (curl_errno($ch)) { 
   print curl_error($ch); 
} 
curl_close($ch); 

有用的链接: curl_errno() curl_error()