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 |
import java.net.*; import java.io.*; import java.util.*; public class ejemplo5 { public static void main(String[] args){ try { String data = "nombre=Hello+World!&edad=23"; URL url = new URL("http://localhost:89/getypost/examplepost.php"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setDoOutput(true); con.getOutputStream().write(data.getBytes("UTF-8")); BufferedReader reader = new BufferedReader(new InputStreamReader(con.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); } } } |