如何取消设置Socks Proxy

时间:2012-10-23 22:53:53

标签: java

我可以通过以下代码设置socks代理服务器:

    System.getProperties().setProperty("socksProxySet", "true");
    System.getProperties().setProperty("socksProxyHost", address);
    System.getProperties().setProperty("socksProxyPort", port);

Accordind http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html,我可以取消设置这样的HTTP,HTTPS和FTP代理:

    System.setProperty("http.proxyHost", null);

问题:我可以取消设置袜子代理吗?

通过做:

    System.getProperties().setProperty("socksProxyHost", null);

我只得到NullPointerException ......

2 个答案:

答案 0 :(得分:2)

使用:

System.clearProperty("http.proxySet");
System.clearProperty("http.proxyHost");
System.clearProperty("http.proxyPort");

这将清除代理设置。

答案 1 :(得分:0)

您可能还需要清除socksProxyPort

socksProxySet是虚构的,什么都不做; ditto httpProxySethttp.proxySethttps.proxySet等,尽管它在几本书中都有所说。

但是,如果你必须使用然后不使用代理,你应该真的使用java.net.Proxy来做这种事情。