简体   繁体   中英

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. I´m trying to consume the New Relic REST service.

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.

<?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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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