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