开发者

How to set Http Proxy in an applet

开发者 https://www.devze.com 2023-03-20 11:41 出处:网络
For a java desktop application after we set these properties System.setProperty(\"java.net.useSystemProxies\",\"true\");

For a java desktop application after we set these properties

System.setProperty("java.net.useSystemProxies","true");
Syste开发者_Python百科m.setProperty("http.proxyHost", "1.1.1.1");
System.setProperty("http.proxyPort", "8080");

every http connection will be done through the defined proxy.

But for an applet these does not work.(In an applet viewer it does but in a browser it doesnt.) Applet always uses these settings which are defined in control panel\java\network settings\proxy settings.

How can i set the proxy in an applet? (Using proxy class in every opening connection is not a solution for me.)

Applet is signed and compiled with java 1.6


I imagine that the real reason that the System properties approach doesn't work is that by the time the applet starts, the Java runtime system has already read the properties and set up the default proxy selector.

Have you tried using ProxySelector? Refer to section 4) of this document.

Of course, this is only likely to work when your applet is a signed applet.


You can do it using API but not for each connection.

Look at URL.openConnection(). It delegates the call to handler. Handler is created by handler factory (if registered). So, you have to register your own factory, create your URL handler that performs URL connection via proxy (calls URL.openConnection(proxy)).

Factory must implement interface URLStreamHandlerFactory and can be registered by calling static method URL.setURLStreamHandlerFactory().

0

精彩评论

暂无评论...
验证码 换一张
取 消