// This sample shows an example of using Internet Explorer to programmatically // POST data to a website. // import iexplorer.InternetExplorer; import iexplorer.IWebBrowserApp; import iexplorer.IWebBrowser2; import ezjcom.JComVariant; public class PostData { public static void main(String args[]) { IWebBrowserApp app = null; try { // Instantiate an InternetExplorer InternetExplorer ie = new InternetExplorer(); // Get IWebBrowserApp app = ie.getIWebBrowserApp(); // Make the browser visible!! app.setVisible( true ); // If IE is trying to load any default pages, stop it. app.Stop(); // The URL to POST to, and the data to POST. String url = "http://localhost/j_security_check"; String postData = "j_username=test&j_password=testpwd"; // NOTE: The post-data must be URL-encoded if there are any unusual characters. // Typically, the content-type application/x-www-form-urlencoded must be used. String headers = "Content-Type: application/x-www-form-urlencoded\r\n"; // Navigate to the URL with a POST app.Navigate( url, new JComVariant(), new JComVariant(), new JComVariant( postData.getBytes()), new JComVariant( headers )); // If the POST data performs a login, then after waiting for the Navigate to // complete, the secure pages can be accessed. } catch (Exception ex) { ex.printStackTrace(); } finally { // Leave the app running // if ( app != null ) // try { app.Quit(); } catch (Exception ex) {} } System.exit(0); } }