Java 调用getProxyInfo时使用BrowserProxyInfo和SunAutoProxyHandler时出现异常
我是Java新手,所以请友善一点:) 我已经看到这段代码到处浮动(在这里和其他地方),并尝试了它,但当我尝试使用它时,我遇到了一个异常 例外情况是: java.security.AccessControlException:拒绝访问(“java.io.FilePermission”“…\nashorn.jar”“读取”) 我的策略文件最初包含: 授予{ 权限java.security.FilePermission“”“读取”; }; 但我在绝望中把它改成了这个,但它仍然不起作用: 授予{ 权限java.security.AllPermission“”; };Java 调用getProxyInfo时使用BrowserProxyInfo和SunAutoProxyHandler时出现异常,java,proxy,Java,Proxy,我是Java新手,所以请友善一点:) 我已经看到这段代码到处浮动(在这里和其他地方),并尝试了它,但当我尝试使用它时,我遇到了一个异常 例外情况是: java.security.AccessControlException:拒绝访问(“java.io.FilePermission”“…\nashorn.jar”“读取”) 我的策略文件最初包含: 授予{ 权限java.security.FilePermission“”“读取”; }; 但我在绝望中把它改成了这个,但它仍然不起作用: 授予{ 权限j
非常感谢您的帮助。您是否已将JVM指向策略文件?命令行上的
-Djava.security.policy=policy.all
或System.setProperty(“java.security.policy”,“c:/folder/to/policy.file”)代码>
import java.net.MalformedURLException;
import java.net.URL;
import com.sun.deploy.net.proxy.BrowserProxyInfo;
import com.sun.deploy.net.proxy.ProxyConfigException;
import com.sun.deploy.net.proxy.ProxyInfo;
import com.sun.deploy.net.proxy.ProxyType;
import com.sun.deploy.net.proxy.ProxyUnavailableException;
import com.sun.deploy.net.proxy.SunAutoProxyHandler;
public static void main(String[] args) throws ProxyConfigException, MalformedURLException, ProxyUnavailableException {
BrowserProxyInfo b = new BrowserProxyInfo();
b.setType(ProxyType.AUTO);
b.setAutoConfigURL("http://localhost/sample.pac");
SunAutoProxyHandler handler = new SunAutoProxyHandler();
handler.init(b);
ProxyInfo[] ps = handler.getProxyInfo(new URL("http://example.net"));
for(ProxyInfo p : ps){
System.out.println(p.toString());
}
}