0
    public HTMLReader(String abc) throws IOException
    {     
            URL url = new URL(abc);

            URLConnection con = url.openConnection();
            InputStream is =con.getInputStream();


            BufferedReader br = new BufferedReader(new InputStreamReader(is));

            String line = null;

            while ((line = br.readLine()) != null&& (exit==false)) 
            {
                 System.out.println(line);
            }
   }

The above is a simple java code that reads html code off a given url of a website. Let's say the given is a Hotmail url https://col130.mail.live.com/default.aspx. When I tired reading the html code for that url, It is giving me the html code of the Hotmail login page, even though I have already signed in to my Hotmail e-mail.

Is there something I should do to be able to read the html code of my e-mail page that is already signed in? Thank you.

jonathan lam
  • 55
  • 1
  • 8
  • You are reading the content of the supplied URL. – PM 77-1 Feb 06 '15 at 05:09
  • when you say "you have signed in", it means your browser has the cookie. Java uses it's own environment, and does not have that cookie. Even another browser would not be signed in either. You need to authenticate in the program, but I don't know what's the api of hotmail. By analogy, cURL provides a way to authenticate against apache authentication system... – Sebas Feb 06 '15 at 05:09

1 Answers1

0

You have signed in through your brwoser (I guess). The browser saves your login information with cookies. Your program does not know about these cookies, so you don't see anything.

So what can you do?
You can send a so called "POST Request" to the page with your login data. This is nothing else than if you enter your login data and click the submit button. A post request is based on key-value pairs. This means, that you have a key, e.g. "password" and a value, e.g. "MyPassw0rd2846".
There is a chrome plugin called "Request Maker" with that you can see any POST or GET requests sent.
For information on how to do POST requests see this or just google.

If you have more questions just ask, Tobias

Community
  • 1
  • 1