1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import java.io.*; import java.net.*; public class PeticionGET { public static void main(String[] args) { try { URL url = new URL("http://localhost:89/getypost/exampleget.php?nombre=Hello+World!&edad=23"); URLConnection conexion = url.openConnection(); // LEER DE LA URL BufferedReader reader = new BufferedReader(new InputStreamReader(conexion.getInputStream())); String linea; while ((linea = reader.readLine()) != null) { System.out.println(linea); } reader.close();// cerrar flujo } catch (MalformedURLException me) { System.err.println("MalformedURLException: " + me); } catch (IOException ioe) { System.err.println("IOException: " + ioe); } }// main } |