-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...

2

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

4 Comments

@Jeff Glad it helps you somehow. See stackoverflow.com/help/someone-answers
Just one last question: I need to add --data-ascii "{body} after the sub key but that is proving difficult to figure out! Grateful if you can help again...
its OK, I sorted the last bit. Thanks again Sunny!
If my answer helps you then you should vote it up and mark it as answer mate :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.