Authenticator Question

N

No Comment

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top