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. Advertisements

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. sean
    Replies:
    1
    Views:
    763
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    939
    Iain Norman
    Feb 16, 2005
  3. =?Utf-8?B?YW5kcmV3MDA3?=

    question row filter (more of sql query question)

    =?Utf-8?B?YW5kcmV3MDA3?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,177
    Scott Allen
    Oct 6, 2005
  4. Elwood P. Dowd
    Replies:
    0
    Views:
    885
    Elwood P. Dowd
    Oct 30, 2003
  5. JohnG
    Replies:
    0
    Views:
    834
    JohnG
    May 6, 2005
  6. freesoft_2000

    Authenticator

    freesoft_2000, Jul 15, 2005, in forum: Java
    Replies:
    2
    Views:
    429
    freesoft_2000
    Jul 23, 2005
  7. notHere

    Authenticator mozilla apache

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

    Fallback Authenticator

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