dongweicha6077 2018-05-04 10:25
浏览 88


I need to get data from an API using curl in PHP, but I have no experience with this?

I've been using PHP for a while now (beginer/intermediate level), but I don't know how to use the curl command or how to make a PHP version of this.

All I know of the API is that to get a list of all the books I kan use:

curl --request GET \
--url '{identifier}'

using "main" as the {identifier}

This is supposed to give me a list of alle the books, and then I can use

curl --request GET \
--url '{identifier}'

to get the (meta) data of the books (Title, Author, Description, Year, Cover)

I've tried using $curl = curl_init(""); and then using curl_setopt_array($curl, array() to get the data, but i get an "WARNING curl_init() has been disabled for security reasons" error.

I'm totally lost and starting from scratch on these API/curl calls...

Hope someone can explain it to me?

(using Xampp on Windows)

  • 写回答

4条回答 默认 最新

  • dongzhizhai4070 2018-05-04 10:38

    First enable curl for your xamp. To do so follow the steps
    1. Go to C:\Program Files\xampp\php\php.ini
    2. Un-comment the following line on your php.ini file by removing the semicolon.
    ;extension=php_curl.dll to extension=php_curl.dll
    3. Restart your apache server.

    Then user thr curl like

    $url= "";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_ENCODING, ""); // this will handle gzip content
    $result = curl_exec($ch);
    print $result;
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序