-
Notifications
You must be signed in to change notification settings - Fork 0
/
curl_api_test.php
executable file
·65 lines (54 loc) · 2.19 KB
/
curl_api_test.php
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/php
<?php
function api_curl_send($url, $json = "")
{
$ch = curl_init();
$httpheader = array(
'Content-Type: ' . 'application/json',
'Accept: ' . 'application/json'
);
$curl_post = 0;
if($json != "")
{
$curl_post = 1;
curl_setopt($ch, CURLOPT_POST, $curl_post);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
$resp = curl_exec($ch);
$info = curl_getinfo($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $resp;
}
/* CALL PLOT ROUTE FROM AIRPORT ONE TO AIRPORT TWO */
// curl -d '{"id_airport1":3484, "id_airport2":9067}' -H "Content-Type: application/json" -X POST http://wonderful.pacificcode.com/api/plot_route
$url = "http://wonderful.pacificcode.com/api/plot_route";
$obj = new stdClass();
$obj->id_airport1 = 3484; // LAX
$obj->id_airport2 = 3830; // Chicago O'Hare
/* CALL GET CLOSET AIRPORTS BY COUNTRY NAME */
// curl -d '{"country1":"United States", "country2":"Russia"}' -H "Content-Type: application/json" -X POST http://wonderful.pacificcode.com/api/airport_by_country
// $url = "http://wonderful.pacificcode.com/api/airport_by_country";
// $obj = new stdClass();
// $obj->country1 = "United States";
// $obj->country2 = "Russia";
/* CALL GET CLOSET AIRPORTS BY RADIUS */
// curl -d '{"lat":33.984305, "lon":-118.463262, "radius":10}' -H "Content-Type: application/json" -X POST http://wonderful.pacificcode.com/api/airport_by_radius
// $url = "http://wonderful.pacificcode.com/api/airport_by_radius";
// $obj = new stdClass();
// $obj->lat = 33.984305;
// $obj->lon = -118.463262;
// $obj->radius = 10;
/* CALL GET DISTANCE BETWEEN TWO AIRPORTS BY ID_AIRPORT */
// curl -d '{"id_airport1":3484, "id_airport2":9067}' -H "Content-Type: application/json" -X POST http://wonderful.pacificcode.com/api/distance_between
// $url = "http://wonderful.pacificcode.com/api/distance_between";
// $obj = new stdClass();
// $obj->id_airport1 = 3484; // LAX
// $obj->id_airport2 = 3830; // Chicago O'Hare
$json = json_encode($obj);
$response = api_curl_send($url, $json);
print_r(json_decode($response));
?>