Does Java's ProxySelector not work with automatic proxy configuration scripts?

前端 未结 5 2100
生来不讨喜
生来不讨喜 2020-12-01 03:14

I want my Java program to use the system\'s proxy configuration. Accordingly, I used the code found in many places, such as this answer, to set java.net.useSystemProxi

5条回答
  •  庸人自扰
    2020-12-01 03:36

    I could load Proxy Auto-Config (PAC) file on Java. Please see below codes and package. I hope this would what you were looking for:

    import com.sun.deploy.net.proxy.*;
    .
    .
    BrowserProxyInfo b = new BrowserProxyInfo();        
    b.setType(ProxyType.AUTO);
    b.setAutoConfigURL("http://yourhost/proxy.file.pac");       
    DummyAutoProxyHandler handler = new DummyAutoProxyHandler();
    handler.init(b);
    
    URL url = new URL("http://host_to_query");
    ProxyInfo[] ps = handler.getProxyInfo(url);     
    for(ProxyInfo p : ps){
        System.out.println(p.toString());
    }
    

    You already have a [com.sun.deploy.net.proxy] package on your machine! Find [deploy.jar] ;D

提交回复
热议问题