Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 filling out forms
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Aeneid




PostPosted: Sat Feb 11, 2006 7:41 pm   Post subject: filling out forms

i have been trying to write code so that i can use java to fill out a form but i can't seem to get it to work. i fill in the form but when i go to read teh response i get the same old page insted of the one i should get after filling out the form.

here is the code i am using. it is not mine actually i got it from somewhere

code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.text.html.*;

public class webwriter
{
    public static void main (String [] arguments)
    {

        PageFrame page = new PageFrame ("http://s1.starkingdoms.com/login.php");
        page.show ();

    }
}

class PageFrame extends JFrame
{
    JTextArea box = new JTextArea ("Getting data ...");
    URL page;

    public PageFrame (String address)
    {
        super (address);
        setSize (600, 300);
        JScrollPane pane = new JScrollPane (box);
        getContentPane ().add (pane);
        WindowListener l = new WindowAdapter ()
        {
            public void windowClosing (WindowEvent evt)
            {
                System.exit (0);
            }
        }
        ;
        addWindowListener (l);

    try {
        // Construct data
        String data = URLEncoder.encode("password") + "=" + URLEncoder.encode("mypassword");
        data += "&" + URLEncoder.encode("account") + "=" + URLEncoder.encode("myaccount");
   
        // Send data
        URL url = new URL("http://www.starkingdoms.com");
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(data);
        wr.flush();
   
        // Get the response
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null) {
            box.append(line + "\n");
        }
        wr.close();
        rd.close();
    } catch (Exception e) {
    }

    }
}


in case it helps i left the site i am trying to access in there.
Sponsor
Sponsor
Sponsor
sponsor
turboliux




PostPosted: Sun Feb 12, 2006 7:01 am   Post subject: (No subject)

use code tag!!!
Aeneid




PostPosted: Sun Feb 12, 2006 2:09 pm   Post subject: (No subject)

code tag what is that?
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: