Question:
How to send the API key of the custom name with file_get_contents?

Problem:

The API I am trying to connect to uses an API key labelled x-openaip-client-id.


<?php


$countryCode = "DE";

$token = "fsdfdsf";



$url = "https://api.core.openaip.net/api/airspaces?type=4&country=" . $countryCode;

$options = array('http' => array(

    'method'  => 'GET',

    'header' => 'Authorization: x-openaip-client-id '.$token

));


$context  = stream_context_create($options);

$raw = file_get_contents($url, false, $context);



$array = json_decode($raw);


print("<pre>".print_r($array,true)."</pre>");


?>



Is there a way to do this with file_get_contents()?


Or must I resort to curl or similar component?


Documentation is at >https://docs.openaip.net


Solution:

As confirmed by the documentation, the header should be just


'header' => 'x-openaip-client-id: '.$token



Suggested blogs:

>How to register a schedule with the controller?

>How to resolve the Composer dependency conflicts (Symfony)?

>How to get item details of Woo Commerce in custom email content?

>PHP cURL to upload video to azure blob storage

>How to merge cells with HTML, CSS, and PHP?





Ritu Singh

Ritu Singh

Submit
0 Answers