-3

I have a cURL GET statement:

curl -v -X GET "https://admiraltyapi.azure-api.net/uktidalapi/api/V1/Stations/{stationId}" -H "Ocp-Apim-Subscription-Key: {subscription key}" --data-ascii "{body}" 

that works fine in a terminal window (with my sub key) - I now want to use it in a PHP script to retrieve the associated JSON. Code suggestions for achieving this appreciated...

Jeff
  • 89
  • 1
  • 12

1 Answers1

0

Not tested but you need something like this with PHP CURL.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://admiraltyapi.azure-api.net/uktidalapi/api/V1/Stations/{stationId}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_TRANSFERTEXT, true);

$headers = array();
$headers[] = 'Ocp-Apim-Subscription-Key: {subscription key}';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103