2

我无法通过 curl 执行 URL。但如果只是通过浏览器运行查询,它工作正常。我的代码是这样的:

$xmlData = "<Leads><row no='1'><FL val='First Name'>".$new_fname."</FL><FL val='Last Name'>".$new_lname."</FL><FL val='Email'>".$new_email."</FL><FL val='Phone'>".$new_ph_no."</FL></row></Leads>";
$xmlData = htmlentities($xmlData);
$ch = curl_init("https://crm.zoho.com/crm/private/xml/Leads/insertRecords?newFormat=1&authtoken=XXX&scope=crmapi&xmlData=".$xmlData);
curl_setopt($ch, CURLOPT_VERBOSE, 1);//standard i/o streams 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);// Turn off the server and peer verification 
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'rsa_rc4_128_sha'); //for godaddy server patch
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//Set to return data to string ($response) 
curl_setopt($ch, CURLOPT_POST, 1);//Regular post 
$response = curl_exec($ch); 
curl_close($ch);

你能告诉我问题出在哪里吗?提前致谢。

4

1 回答 1

1

以下代码应该可以工作:

$ch = curl_init("https://crm.zoho.com/crm/private/xml/Leads/insertRecords?newFormat=1&authtoken=XXX&scope=crmapi&xmlData=".$xmlData);

curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// deactivate certificate checking 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//Set to return data to string ($response) 
curl_setopt($ch, CURLOPT_POST, 1);//Regular post 
$response = curl_exec($ch); 

if(!$response) {
    echo curl_error($ch), PHP_EOL;
}
curl_close($ch);

经过讨论评论后,我意识到问题在于您尚未在系统上安装 Thawte ssl 证书。你有两个选择:

  • 安装证书
  • 使用禁用证书检查CURLOPT_VERIFYPEER = FALSE

我在示例中使用了第二种方法,只是为了展示如何使您的代码正常工作。对于生产系统,我建议您安装证书。

于 2013-02-06T11:53:31.957 回答