简体   繁体   English

从New Relic API将line comand curl转换为PHP curl

[英]Convert line comand curl to PHP curl from New Relic API

i would like to have some help how to convert a comand line request via curl to the PHP curl. 我想对如何通过curl将comand行请求转换为PHP curl有所帮助。 I´m trying to consume the New Relic REST service. 我正在尝试使用New Relic REST服务。

The sample code is like this: 示例代码如下:

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

Thanks in advance! 提前致谢!

You could use curl_setopt_array() instead of curl command line flags. 您可以使用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);

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

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