-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02demo-curl.php
More file actions
33 lines (24 loc) · 905 Bytes
/
02demo-curl.php
File metadata and controls
33 lines (24 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
//using curl for api call
$ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, );
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//set headers
$headers = [
"Authorization: Client-ID A1XKO9j45wVD3gjxvLicqMyiIfOx1ekm9UMMIUsjrbQ"
];
curl_setopt_array($ch, [
// CURLOPT_URL => 'http://api.weatherapi.com/v1/current.json?key=e81d26fea2c54855b4d153248251506&q=Bhubaneswar&aqi=yes',
CURLOPT_URL => 'https://api.unsplash.com/photos/random',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers
]);
// Execute the cURL request and get the response
// This will return the response as a string instead of outputting it directly
$response = curl_exec($ch);
//get the http status code
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Output the response and status code
echo "HTTP Status Code: " . $statusCode . PHP_EOL;
echo $response . PHP_EOL;