Das ist zur zeit mein aktueller stand...
import java.io.DataInputStream;
import java.io.FileOutputStream;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Properties;
public class test001 {
public static void main(String args[])
{
dump("http://www.yahoo.com");
System.out.println("**************");
dump("https://www.paypal.com");
System.out.println("**************");
dump("https://my-url.xy");
System.out.println("**************");
}
public static void dump(String URLName) {
Authenticator.setDefault(new MyAuthenticator());
try {
DataInputStream di = null;
FileOutputStream fo = null;
String proxy = "my-company.proxy.de";
String port = "8080";
String userPw = "user.name:password";
byte[] b = new byte[1];
// PROXY
Properties systemSettings = System.getProperties();
systemSettings.put("http.proxyHost", proxy);
systemSettings.put("http.proxyPort", port);
URL u = new URL(URLName);
HttpURLConnection con = (HttpURLConnection) u.openConnection();
// HttpURLConnection.setFollowRedirects(true);
// con.setInstanceFollowRedirects(false);
//Base64Coder encoder = new Base64Coder();
String encodedUserPwd = Base64Coder.encode(userPw.getBytes());
con.setRequestProperty("Proxy-Authorization", "Basic " + encodedUserPwd);
// PROXY ----------
di = new DataInputStream(con.getInputStream());
while (-1 != di.read(b, 0, 1)) {
System.out.print(new String();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
[/code]
Gebe ich nur die Basis-URL ein sehe ich zumindest schon mal den HTML-Code. Gebe ich aber die
Adresse zu dem Download an, bekomme ich folgenden Fehler:
[code]
java.net.ProtocolException: Server redirected too many times (20)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:318)
at test001.dump(test001.java:55)
at test001.main(test001.java:17)
Im Internet habe ich dazu gefunden das es einen Redirect gibt der nicht automatisch verfolgt wird. Die
Lösung dazu ist der Auskommentierte teil
HttpURLConnection.setFollowRedirects(true);
con.setInstanceFollowRedirects(false);
Lass ich mir aber die URL, der ich folgen soll, ausgeben con.getHeaderField("Location")ist es eine
interne Adresse des Zielsystems (http://123.456.78.90:8080)
Ich drehe mich jetzt etwas im Kreis... Ursprünglich wollte ich das mittels XMLhttpRequest
(HttpClient - HttpClient Home) lösen in der Hoffnung, dass ich die Klasse in etwa so benutzen könne
wie die Implementierung unter VBA. Dies zeigte sich aber als komplizierter als erwartet...
Jetzt habe ich den Gedanken gehabt, dass ich den Download mit Java-Boardmitteln lösen könne.
Komme aber mit dem obigen Code auch nicht weiter...
Hat hier noch jemand einen guten Gedanke?
Gruß
Oggie85