2013-02-06 73 views
2

我无法通过curl执行URL。但是,如果简单地运行查询thrugh浏览器,它的工作正常。我的代码是这样的:无法通过卷曲执行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); 

您能否让我知道问题在哪里? 在此先感谢。

+2

你能描述你遇到的实际问题/错误吗? –

+0

使用'curl_error()'来查看问题出在哪里 –

+0

你通过浏览器发出了一个post请求? –

回答

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

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

+0

我收到以下错误: SSL证书问题,请验证CA证书是否正常。详细信息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败 – Srimanta

+0

检查我的输出http://pastxt.com/P/5Y2I09WROO – hek2mgl

+0

但在您的方案中,它显示“SSL证书确认无误”,但它为什么是现在为我显示,而我正在得到错误。 – Srimanta