Server redirected too many times - authentication issue

Discussion in 'Java' started by konrad-g@o2.pl, Feb 17, 2006.

  1. Guest

    Hello,

    here's my problem. I'm writing a crawler which needs to access password
    protected ASP pages. I know the password protected URL, but accessing
    it without login invokes login screen, which (after logging in)
    redirects me back to the page. I know URL of that login page too.

    Here's my code:

    /************** Code begins *************/
    URL url = new URL( urlString );
    HttpURLConnection c = (HttpURLConnection)url.openConnection();
    c.setRequestMethod("POST");
    c.setDoInput(true);
    c.setDoOutput(true);
    c.setUseCaches(false);
    OutputStream urlOut = c.getOutputStream();
    urlOut.write(("LoginControl1:txtEmail="+URLEncoder.encode("login")+"&LoginC­ontrol1:txtPassword="+URLEncoder.encode("pass")).getBytes());



    InputStream content = (InputStream)c.getInputStream();
    BufferedReader in = new BufferedReader (new InputStreamReader
    (content));
    String line;
    while ((line = in.readLine()) != null) System.out.println (line);
    /************** Code ends *************/

    I tried to set up urlString for two values. First of them is login
    page, which (after logging in) should redirect me to desired page.
    Using it ends up with "Server redirected too
    many times" exception. The second option is using desired page's URL
    as urlString - but in this case final "while" loop produces login
    screen instead of desired page.

    Any clues?

    Thanks in advance,
    Konrad Garus
     
    , Feb 17, 2006
    #1
    1. Advertising

  2. wrote:

    > I tried to set up urlString for two values. First of them is login
    > page, which (after logging in) should redirect me to desired page.
    > Using it ends up with "Server redirected too
    > many times" exception. The second option is using desired page's URL
    > as urlString - but in this case final "while" loop produces login
    > screen instead of desired page.


    It seems to me that you have ended up in an infinite loop, which the
    server is detecting and in the end warning you about. What is probably
    happening is that you are not performing a correct login so you are
    routed back to the original page, which are routing you to the login
    page, where you fail and so on. Not sure if that is correct but it would
    seem like it.

    So I suggest two things, confirm that this or something similar is the
    case first. You can do this by adding code which performs the login
    sequence once. Then you print what you are sending and what you are
    receiving to check or study whats going on.
    Secondly, you need to find out the correct way to perform login. If it
    uses HTTP Authentication, which it seems like since you are describing a
    login pop up, then its easy to solve this programatically just read the
    rfc. If it is a custom made login page, then you need the details of it
    to solve the puzzle.

    /tom
     
    tom fredriksen, Feb 18, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmVzcGVyIE9yZHJ1cCBDaHJpc3RlbnNlbg==?=

    events fireing too many times?

    =?Utf-8?B?SmVzcGVyIE9yZHJ1cCBDaHJpc3RlbnNlbg==?=, Aug 22, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    366
    =?Utf-8?B?SmVzcGVyIE9yZHJ1cCBDaHJpc3RlbnNlbg==?=
    Aug 22, 2004
  2. Manuel
    Replies:
    9
    Views:
    700
    John Saunders
    Dec 16, 2004
  3. Lukasz
    Replies:
    0
    Views:
    4,652
    Lukasz
    Sep 21, 2004
  4. Daniel Pitts
    Replies:
    0
    Views:
    517
    Daniel Pitts
    Oct 18, 2007
  5. Pete Coolidge

    OnItemCreated and OnItemDataBound called too many times?

    Pete Coolidge, Jul 4, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    278
    Pete Coolidge
    Jul 4, 2003
Loading...

Share This Page