Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 调用getProxyInfo时使用BrowserProxyInfo和SunAutoProxyHandler时出现异常_Java_Proxy - Fatal编程技术网

Java 调用getProxyInfo时使用BrowserProxyInfo和SunAutoProxyHandler时出现异常

Java 调用getProxyInfo时使用BrowserProxyInfo和SunAutoProxyHandler时出现异常,java,proxy,Java,Proxy,我是Java新手,所以请友善一点:) 我已经看到这段代码到处浮动(在这里和其他地方),并尝试了它,但当我尝试使用它时,我遇到了一个异常 例外情况是: java.security.AccessControlException:拒绝访问(“java.io.FilePermission”“…\nashorn.jar”“读取”) 我的策略文件最初包含: 授予{ 权限java.security.FilePermission“”“读取”; }; 但我在绝望中把它改成了这个,但它仍然不起作用: 授予{ 权限j

我是Java新手,所以请友善一点:)

我已经看到这段代码到处浮动(在这里和其他地方),并尝试了它,但当我尝试使用它时,我遇到了一个异常

例外情况是:

java.security.AccessControlException:拒绝访问(“java.io.FilePermission”“…\nashorn.jar”“读取”)

我的策略文件最初包含:

授予{ 权限java.security.FilePermission“”“读取”; };

但我在绝望中把它改成了这个,但它仍然不起作用:

授予{ 权限java.security.AllPermission“”; };


非常感谢您的帮助。

您是否已将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());
    }

}