Results 1 to 10 of 10
  1. #1
    traktor is offline Member
    Join Date
    Sep 2013
    Posts
    4
    Rep Power
    0

    Default Accessing site using user credentials stored in a browser

    Hi!

    I wish to read a site from Java ([Moderator edit: URL removed]this site[]). When I go to the site in a Google Chrome window, I immediately get to the contents I desire, since I am logged to the site per default in Chrome (the user credentials are stored in the browser)

    However, if I go to the same site using, java.io.URL, I don't access the desired contents (rather, a redirect is made to a login site). Is there anyway I can tell the java.io.URL to make the connection using the user credentials stored in Chrome? Or is there any other way I can get to the site, maybe by somehow specifying the user credentials in Java?
    Last edited by DarrylBurke; 09-01-2013 at 11:22 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Accessing site using user credentials stored in a browser

    You'd have to find the relevant cookie in whatever place Chrome stores those sort of things.
    Or IE.
    Or Firefox.
    etc etc.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    traktor is offline Member
    Join Date
    Sep 2013
    Posts
    4
    Rep Power
    0

    Default Re: Accessing site using user credentials stored in a browser

    Thanks, I found a cookie in Chrome, but then another problem arises when I try to get the page from Java: it says that "We've detected that you're using an unsupported browser. Please upgrade to one of these more modern browsers". Is there anyway around this?

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: Accessing site using user credentials stored in a browser

    Probably you'll have to set proper request headers, most notably the user agent. If you set one that a popular browser uses, you will fool the website into thinking you're using that browser.

    User agent - Wikipedia, the free encyclopedia
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Accessing site using user credentials stored in a browser

    You could bluff.
    Part of the request header contains the browser type, so dig out that bit and set it something new.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Accessing site using user credentials stored in a browser

    Beaten by seconds, and he gets a linnk in!
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: Accessing site using user credentials stored in a browser

    Worse: I was even contemplating for a moment if I would post or not, since without having a valid reasoning to bypass a browser to access the site I find it a bit of a shady question.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Accessing site using user credentials stored in a browser

    Oh, I don't know.
    Not sure I see the shadiness...

    (And I'm just dead slow, me)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    traktor is offline Member
    Join Date
    Sep 2013
    Posts
    4
    Rep Power
    0

    Default Re: Accessing site using user credentials stored in a browser

    I went to Whats My User Agent? with a browser that I can use to access the site, found the User Agent and wrote the following:

    Java Code:
    	URL obj = new URL(url);
    	conn = (HttpsURLConnection) obj.openConnection();
    
    	conn.setRequestMethod("GET"); 
    	conn.setUseCaches(false);
     
    	// act like a browser
            String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36";//"Mozilla/5.0";
    
    	conn.setRequestProperty("User-Agent", USER_AGENT);
    	conn.setRequestProperty("Accept",
    		"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    	conn.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
    
    	conn.addRequestProperty("Cookie", "<<The cookie that i found stored by Chrome>>");
    
    BufferedReader in = 
                new BufferedReader(new InputStreamReader(conn.getInputStream()));
    	String inputLine;
    	StringBuffer response = new StringBuffer();
     
    	while ((inputLine = in.readLine()) != null) {
    		response.append(inputLine);
    	}
    	in.close();
     
    	System.out.println(response.toString());
    But I still get a page containing the "unsupported browser" message :( Why can that be?

  10. #10
    traktor is offline Member
    Join Date
    Sep 2013
    Posts
    4
    Rep Power
    0

    Default Re: Accessing site using user credentials stored in a browser

    No worries folks, there are no shady intentions here so if you can guide me in the right direction please do so!

Similar Threads

  1. How to get user input stored in an array
    By ryan4509 in forum New To Java
    Replies: 3
    Last Post: 06-09-2013, 01:50 AM
  2. Replies: 3
    Last Post: 09-15-2012, 05:29 PM
  3. Accessing objects stored in an array list or set
    By kev3kev3 in forum New To Java
    Replies: 6
    Last Post: 04-24-2012, 07:10 PM
  4. Replies: 0
    Last Post: 09-24-2010, 07:11 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
  •