hey,
sorry erstmal, dass ich das thema aufmache, aber ich hab schon alle googleergebnisse abgegrast und nix hat geholfen. Also folgendes: ich hab ein programm, das über einen proxy ins internet soll. dazu brauch ich eine HttpURLConnection. leider muss dieses Programm hinter einem Proxy laufen. ich muss also eine HttpURLconnection machen, die über einen Proxy läuft. dazu hab ich 2 ansätze, beide verbinden sich zwar (mein computer ist hier auch so am internet) aber beide nicht über den proxy. der rest des programms läuft soweit.
1ster Ansatz:
Ergibt folgende Ausgabe:
Funktioniert also nich. der proxyllog zeigt auch nichts an.
2ter Ansatz:
Ergibt:
false
funktioniert also beides nicht, hat irgendwer einen rat?
danke schonmal
martin
sorry erstmal, dass ich das thema aufmache, aber ich hab schon alle googleergebnisse abgegrast und nix hat geholfen. Also folgendes: ich hab ein programm, das über einen proxy ins internet soll. dazu brauch ich eine HttpURLConnection. leider muss dieses Programm hinter einem Proxy laufen. ich muss also eine HttpURLconnection machen, die über einen Proxy läuft. dazu hab ich 2 ansätze, beide verbinden sich zwar (mein computer ist hier auch so am internet) aber beide nicht über den proxy. der rest des programms läuft soweit.
1ster Ansatz:
Code:
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyHost", main.getProxy());
System.setProperty("http.proxyPort", String.valueOf(main.getProxyPort()));
System.out.println(System.getProperty("http.proxyHost"));
System.out.println(System.getProperty("http.proxyPort"));
URL url = main.getURL();
HttpURLConnection urlc;
urlc = (HttpURLConnection)(url.openConnection());
urlc.setDoOutput(true);
System.out.println(urlc.usingProxy());
Ergibt folgende Ausgabe:
Code:
127.0.0.1
3128
false
2ter Ansatz:
Code:
URL url = main.getURL();
HttpURLConnection urlc;
Proxy pr;
int port = main.getProxyPort();
if(port < 1) {
port = 80;
}
InetAddress ip = Inet4Address.getByName(main.getProxy());
InetSocketAddress sa = new InetSocketAddress(ip,port);
pr = new Proxy(Proxy.Type.HTTP, sa);
urlc = (HttpURLConnection)(url.openConnection(pr));
urlc.setDoOutput(true);
System.out.println(urlc.usingProxy());
false
funktioniert also beides nicht, hat irgendwer einen rat?
danke schonmal
martin