【问题标题】:Convert line comand curl to PHP curl from New Relic API从 New Relic API 将 line 命令 curl 转换为 PHP curl
【发布时间】:2014-09-10 13:32:34
【问题描述】:

我想获得一些帮助,如何将命令行请求通过 curl 转换为 PHP curl。我正在尝试使用 New Relic REST 服务。

示例代码如下:

curl -X GET 'https://api.newrelic.com/v2/applications.json' \
     -H 'X-Api-Key:100' -i 

提前致谢!

【问题讨论】:

    标签: php rest curl newrelic


    【解决方案1】:

    您可以使用 curl_setopt_array() 代替 curl 命令行标志。

    <?php
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://api.newrelic.com/v2/applications.json', //URL to the API
        CURLOPT_HEADER => true, // Instead of the "-i" flag
        CURLOPT_HTTPHEADER => array('X-Api-Key:100') //Your New Relic API key
    ));
    $resp = curl_exec($curl);
    curl_close($curl); 
    print_r($resp);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-04
      • 1970-01-01
      • 1970-01-01
      • 2017-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多