exec在PHP中返回null

exec在PHP中返回null

本文介绍了Curl_exec在PHP中返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用curl操作获取数据时遇到问题。在这里我隐藏了令牌,如果我仅在浏览器中使用url,则它将返回数据,但在此处为空。

I have a problem to get the data using curl operation. Here i hide the token, If i use the url only in my browser then it returns the data but here its null.

<?php
$token = "TOKEN"; //the actual token hidden
$url = "https://crm.zoho.com/crm/private/xml/Leads/getRecords?authtoken=".$token."&scope=crmapi";
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);

$result = curl_exec($ch);
curl_close($ch);
echo $result; //does not return anything
?>

如果我做错了,请帮助我。

Where i do mistake please help me.

推荐答案

这是尝试使用 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_exec在PHP中返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 01:45