简体   繁体   English

CURL在进行Api呼叫中的用法

[英]CURL Usage in making Api Call

Can someone suggest me to make curl api call for these syntax 有人可以建议我让curl API调用这些语法

curl -u john.doe@mycompany.com:c14b85863755158d7aa5cc4ba17f61cb -H X-API-Version:2 https://api.livechatinc.com/agents

I tried to use this code but not succeed 我尝试使用此代码,但未成功

$url = john.doe@mycompany.com:c14b85863755158d7aa5cc4ba17f61cb@https://api.livechatinc.com/offline_messages";
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_exec($ch);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$results = curl_exec($ch);
curl_close($ch);
echo '<pre>';print_r($results);

You can find curl library for CodeIgniter framework here from the developer site itself. 您可以从开发人员站点本身在这里找到CodeIgniter框架的curl库 Load the library in your controller like below. 如下所示将库加载到控制器中。

$this->load->spark('curl');

and make a simple call to your api using curl simple_get method like below and save the response in a variable. 并使用如下所示的curl simple_get方法对您的api进行简单调用,并将响应保存在变量中。 Use it based on how you are getting either JSON/XML. 根据您获取JSON / XML的方式来使用它。

$this->curl->simple_get('http://example.com/');

For reference please visit this link. 参考,请访问此链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM