Bonjour
Soit tu déclares ces variables d'environnement au démarrage de ton programme
1 2
| java -classpath ./bin -Dhttp.proxyHost=webcache.mydomain.com -Dhttp.proxyPort=8080
-Dhttp.noProxyHosts=localhost|host.mydomain.com GetURL |
ou coulé dans le bronze dans ton code (mauvais réflexe)
1 2 3 4 5 6 7 8 9 10 11 12 13
| //Set the http proxy to webcache.mydomain.com:8080
System.setProperty("http.proxyHost", "webcache.mydomain.com");
System.setPropery("http.proxyPort", "8080");
// Next connection will be through proxy.
URL url = new URL("http://java.sun.com/");
InputStream in = url.openStream();
// Now, let's 'unset' the proxy.
System.setProperty("http.proxyHost", null);
// From now on http connections will be done directly. |
Il serait préférable de lire la configuration depuis par exemple un fichier de configuration.
Les exemples ont été repris depuis la page de Sun concernant
"Java Networking and Proxies".
Partager