Results 1 to 6 of 6
  1. #1
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Command line browser

    I'm trying to make a command line web browser. But I'm not sure where to start.
    Where should I start?

  2. #2
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default Re: Command line browser


  3. #3
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Re: Command line browser

    Quote Originally Posted by ra4king View Post
    I have looked into it. Thanks.
    But how can I save cookies?
    And I wasn't sure how to redirect to a different page.

  4. #4
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default Re: Command line browser

    Redirect is either an HTTP or HTML level command. The HTTP redirect code is 301, while in HTML, you use
    Java Code:
    <meta http-equiv="refresh" content="0; URL=http://website.to.redirect.to.com">

  5. #5
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Re: Command line browser

    I have found out how to store cookies.
    But when I try to login to a website it takes me back to the index page.
    This is what I use to login:
    Java Code:
    Cookies cm = new Cookies();
            try {
    
                String data = URLEncoder.encode("email", "utf-8") + "=" + URLEncoder.encode("email", "utf-8");
                data += "&" + URLEncoder.encode("pass", "utf-8") + "=" + URLEncoder.encode("pass", "utf-8");
    
    
                URL url = new URL("websitewhereilogin");
                URLConnection conn = url.openConnection();
    
                conn.setDoOutput(true);
                cm.setCookies(conn);
    
                conn.connect();
    
                OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
                wr.write(data);
                wr.flush();
    
    
                cm.storeCookies(conn);
    
    
                System.out.println(cm);
    
    
                BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                                conn.getInputStream()));
    
                String inputLine;
    
                while ((inputLine = in.readLine()) != null) {
                    System.out.println(inputLine);
                }
    
    
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }

  6. #6
    Grkn is offline Member
    Join Date
    Oct 2011
    Posts
    65
    Rep Power
    0

    Default Re: Command line browser

    I wish it can be that simple to login a website.

    Some websites have strict connection security. You have to get auth .....
    You have to dig in these stuffs

    But if you login a regular web page, Then you can get the web page content and parse to find neccessary login tags.

    ex: <form ....... method='POST'>
    <input type='text' value="" name="accountName".....>
    <input type='password' value="" name="accPassword">
    <input type='text' hidden....>
    <button Submit>
    </form>
    //You have to know at least basic html to understand this.
    Detect neccessary inputs first, like accountName, accPassword(There can be other things in hidden). Then form method is POST so it will be sent in invisible string.
    you have to send URL+posted information to destination URL. ( & can not be used instead use &amp)

    Use URLEncoder but don't divide the information
    String URL=".............";
    URLEncoder.encode(URL+"blalba=bla&aa=aa1","UTF-8");

Similar Threads

  1. Replies: 16
    Last Post: 09-17-2011, 02:41 AM
  2. can i run line by line command in netbean?
    By choconlongxu in forum NetBeans
    Replies: 1
    Last Post: 07-19-2010, 08:41 PM
  3. Replies: 2
    Last Post: 07-02-2010, 02:20 PM
  4. Javascript browser command line, broswer communication
    By stevemilw in forum New To Java
    Replies: 0
    Last Post: 07-09-2009, 02:03 PM
  5. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 AM

Posting Permissions

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