Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default Submitting HTML forms through Java help

    Hi, I am trying to fill out a form and then submit it through java. The website I am trying to do this for is, https://services.jsatech.com/index.php?cid=40. I want to be able to fill out the form and then submit it and get the webpage on the other end of the process. Below I have the code I am using thus far but have no idea if it is even right. If anyone can help that would be great.

    Thanks


    Java Code:
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.PrintStream;
    import java.net.URL;
    
    import javax.net.ssl.HttpsURLConnection;
    
    
    public class main {
    	public static void main(String[] args) {
    		try
    	    {
    	      URL url = new URL("https://services.jsatech.com/index.php?cid=40&");
    	 
    	      HttpsURLConnection hConnection = (HttpsURLConnection)
    	                             url.openConnection();
    	      HttpsURLConnection.setFollowRedirects( true );
    	 
    	      hConnection.setDoOutput( true );
    	      hConnection.setRequestMethod("POST");	
    	 
    	      PrintStream ps = new PrintStream( hConnection.getOutputStream() );
    	      ps.print("loginphrase=810488002&password=gyroman123");
    	      ps.close();
    	 
    	      hConnection.connect();
    	 	      
    	      if( HttpsURLConnection.HTTP_OK == hConnection.getResponseCode() )
    	      {
    	    	BufferedReader is = new BufferedReader(new InputStreamReader(hConnection.getInputStream()));
    	        String str = " ";
    	        String whole = " ";
    	        while((str=is.readLine()) != null)
    	        {
    	          whole += str;
    	        }
    	        is.close();
    	        hConnection.disconnect();
    	        System.out.println(whole);
    	      }
    	    }
    	    catch(Exception ex)
    	    {
    	      ex.printStackTrace();
    	    }
    	}
    
    }
    Last edited by Eranga; 11-14-2010 at 01:35 AM. Reason: code tags added

  2. #2
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default

    bump...anyone?

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Please use code tags when you are posting code segments here in the forum. Unformated codes are really hard to read. If you don't know how to do that check in my forum signature. You can find a link to relevant article about that.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by MysticalMagnet View Post
    bump...anyone?
    To check it correct or not you've to test it. Did you do that? Did you end with an error?

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Think about the naming conversions as well. The main is not a good choice for the class name, because it's not really reflect what your class does. So and so...

Similar Threads

  1. Help with two java forms
    By SeaStorm in forum AWT / Swing
    Replies: 3
    Last Post: 05-03-2010, 12:53 AM
  2. Replies: 2
    Last Post: 04-28-2008, 10:56 AM
  3. Full Forms of Java Tech
    By Gajesh Tripathi in forum New To Java
    Replies: 1
    Last Post: 10-18-2007, 09:59 AM
  4. Creating Sub forms in java netbeans 5.0
    By java_newbie in forum NetBeans
    Replies: 14
    Last Post: 08-06-2007, 07:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •