Java code
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 | package post; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; import java.net.HttpURLConnection; import java.net.URL; public class HttpPostForm { public static void main(String[] args) { try { URL url = new URL( "http://www.aaaa.com/xyz.asp" ); HttpURLConnection hConnection = (HttpURLConnection) url.openConnection(); HttpURLConnection.setFollowRedirects( true ); hConnection.setDoOutput( true ); hConnection.setRequestMethod("POST"); PrintStream ps = new PrintStream( hConnection.getOutputStream() ); ps.print("param1=abcd&param2=10341"); ps.close(); hConnection.connect(); if( HttpURLConnection.HTTP_OK == hConnection.getResponseCode() ) { InputStream is = hConnection.getInputStream(); OutputStream os = new FileOutputStream("output.html"); int data; while((data=is.read()) != -1) { os.write(data); } is.close(); os.close(); hConnection.disconnect(); } } catch(Exception ex) { ex.printStackTrace(); } } } |

