首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用Php和Curl运行Rest API

无法使用Php和Curl运行Rest API
EN

Stack Overflow用户
提问于 2020-01-22 19:22:31
回答 1查看 142关注 0票数 2

我已经创建了使用第一版的Zoho API,现在他们迁移到第二版,我的使用curl函数的第一版php代码工作得很好,如下所述。

代码语言:javascript
复制
<?php
$auth="a5014536e7303c218e983f9b2da7ae00";
$xml= "
<Leads>
<row no="1">
<FL val="City">Chennai</FL>
</row>
</Leads>
";
$result = insert($auth,$xml);
print_r($result);

function insert($auth,$xml)
{
$curl_url ="https://crm.zoho.in/crm/private/xml/Leads/insertRecords";
$curl_post_fields= "authtoken=".'$auth'.&scope=crmapi&xmlData=".$xml."";
$ch = curl_int();
curl_setopt( $ch, CURLOPT_URL, $curl_url);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION,true);
curl_setopt( $ch, CURLOPT_TIMEOUT,60);
curl_setopt( $ch, CURLOPT_POST,1);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER,true);
curl_setopt( $ch, CURLOPT_POSTFIELDS,$curl_post_fields);
$response= curl_exec($ch);
curl_close($ch);
return $response;
}
?> 

但是当我使用ZOHO Documention API Documentation 1 API Documentation 2迁移到第二个版本时,它不能运行,我不知道为什么有时它会出现白屏错误500次,下面是版本2代码。

代码语言:javascript
复制
<?php
   $apiUrl = "https://www.zohoapis.com/crm/v2/Leads/";

$fields = json_encode(array("data" => array(["City" => "Egham"])));

$headers = array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($fields),
    'Authorization: Zoho-oauthtoken 4869c41171910edf553c07461c59a059',

);


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$response = curl_exec($ch);
curl_close($ch);
return $response;
?>

有没有人能告诉我哪里做错了,或者能帮我修改代码?

EN

回答 1

Stack Overflow用户

发布于 2020-01-22 19:33:45

将API URL替换为

代码语言:javascript
复制
$apiUrl = "https://www.zohoapis.com/crm/v2/Leads/";

代码语言:javascript
复制
$apiUrl = "https://www.zohoapis.com/crm/v2/Leads";
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59858610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档