无法通过卷曲执行网址

时间:2013-02-06 10:59:43

标签: php curl

我无法通过curl执行网址。但如果只是运行查询thrugh浏览器,它的工作正常。我的代码就像:

$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);
你可以告诉我这个问题在哪里吗? 提前谢谢。

1 个答案:

答案 0 :(得分: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证书。您有两种选择:

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

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