Authenticator Question

Discussion in 'Java' started by No Comment, Nov 11, 2004.

  1. No Comment

    No Comment Guest

    I am attempting to retrieve a file from a URL secured by IDC Security. I am
    using the following to attempt to code for this:

    import java.net.Authenticator;

    import java.net.PasswordAuthentication;

    public class MyAuthenticator extends Authenticator {

    protected PasswordAuthentication getPasswordAuthentication() {

    String userName = "username";

    String password = "password";


    return new PasswordAuthentication(userName, password.toCharArray());

    -------------------------------------------------

    URL url = new URL(sourceName);

    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

    Authenticator.setDefault(new MyAuthenticator());

    ((HttpURLConnection) urlConnection).setInstanceFollowRedirects(false);

    InputStream inputStream = url.openStream();

    // Now we can create our output stream, the new file name is applied here:

    FileOutputStream fileOutputStream = new FileOutputStream(destinationName);

    .....



    I am getting the message 'Server redirected to many times (5)' and a return
    status code of 401, Unauthorized. Yet I am able to retrieve the file via my
    browser with the same login credentials.

    Can anyone tell me what I might be doing wrong?


    Thanks,

    Mark
     
    No Comment, Nov 11, 2004
    #1
    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. Elwood P. Dowd
    Replies:
    0
    Views:
    807
    Elwood P. Dowd
    Oct 30, 2003
  2. JohnG
    Replies:
    0
    Views:
    775
    JohnG
    May 6, 2005
  3. freesoft_2000

    Authenticator

    freesoft_2000, Jul 15, 2005, in forum: Java
    Replies:
    2
    Views:
    347
    freesoft_2000
    Jul 23, 2005
  4. notHere

    Authenticator mozilla apache

    notHere, Oct 12, 2005, in forum: Java
    Replies:
    2
    Views:
    455
    notHere
    Oct 13, 2005
  5. Marian Schedenig

    Fallback Authenticator

    Marian Schedenig, Dec 3, 2007, in forum: Java
    Replies:
    0
    Views:
    316
    Marian Schedenig
    Dec 3, 2007
Loading...

Share This Page