"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." )); }