| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- header('Access-Control-Allow-Origin: *');
- header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method");
- header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
- header("Allow: GET, POST, OPTIONS, PUT, DELETE");
- if($_SERVER['REQUEST_METHOD'] == "POST"){
- if(empty($_POST)){
- echo json_encode(array(
- "status" => "error",
- "results" => "Por favor ingresa los campos necesarios."
- ));
- exit;
- }
- if(!isset($_POST["LAT"])){
- echo json_encode(array(
- "status" => "error",
- "results" => "El LAT es un campo necesario."
- ));
- exit;
- }
- if(!isset($_POST["LON"])){
- echo json_encode(array(
- "status" => "error",
- "results" => "El LON es un campo necesario."
- ));
- exit;
- }
- try{
- $ch = curl_init();
- if($ch === false){
- echo json_encode(array(
- "status" => "error",
- "results" => "Fallo al inicializar CURL."
- ));
- exit;
- }
- $lat = $_POST["LAT"];
- $lon = $_POST["LON"];
- $url = "https://api.opentopodata.org/v1/test-dataset?locations=$lat,$lon";
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $out = curl_exec($ch);
- if($out === false){
- echo json_encode(array(
- "status" => "error",
- "results" => 'Error: ' . curl_errno($ch) . ". Msg: " . curl_error($ch)
- ));
- exit;
- }
- echo $out;
- }catch(Exception $e){
- echo json_encode(array(
- "status" => "error",
- "results" => "Error al ejecutar la petición."
- ));
- }finally{
- if (is_resource($ch)) {
- curl_close($ch);
- }
- }
- }else{
- echo json_encode(array(
- "status" => "error",
- "results" => "Bad Request."
- ));
- }
|