Redirecting to new page after loging using HttpsURLConnection

Posted on 2006-04-01
Last Modified: 2008-01-09
I have following task:
1. login to yahoo
2. after successful login go to
3. parse some information e.g. stock quote
4. I want to repeat operation each 5 minutes to get the same , refreshed page, so do I have to re-establish connection or reuse existing one with refresh mechanizm ?

I was able to finish 1. connect but result looks like this:
<script language="JavaScript">
// -->
<meta http-equiv="Refresh" content="0; url=">
If you are seeing this page, your browser settings prevent you
from automatically redirecting to a new URL.
Please <a href="">click here</a> to continue.

so it looks, after login i am not redirecting but in my code
I am using HttpsURLConnection.setFollowRedirects(true);
so It shoud work. My guess is , that javscript is not executed.

thanks in advance for any help

Question by:lez60
    LVL 14

    Expert Comment

    not sure but use
    LVL 14

    Expert Comment

    setFollowRedirects() should be invoked before url.openConnection() otherwise it wont work then you have to call setInstanceFollowRedirects()
    LVL 14

    Expert Comment

    man, dont you think that HttpUrlConnection doesn't parse the html content and it cant understand javascript ? you need to do it manualy
    LVL 14

    Accepted Solution

    as a last comment
    I found that setFolowRedirects just follows the http redirect instructions
    i.e in php you use header('Location: '. $to);  to send a raw http header
    setFolowRedirects is by default true
    I have tested it on my local apache server and it worked fine (no need to serFolowRedirects(true))
    the page you are viewing is attempting to redirect with two different mechanisms a javascript and an html (<meta http-equiv="Refresh") and non of them is understandable by HttpUrlConnection alone,
    and the only way is to parse the html result and find window.location is assigned to what and the go there manualy

    assume this code
    HttpURLConnection con = (HttpURLConnection) HOST.openConnection();
    con.setInstanceFollowRedirects(false); // as i told dont use static method setFollowRedirects() after openconnection

    then if you look through header fileds --> con.getHeaderFieldKey(index) and con.getHeaderField(index);
    you can see a filed with name:location and value:redirect location
    it is through this header that HttpURLConnection realizes redirection and no other way

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now