How to use automatic proxy configuration script in Java

前端 未结 4 1553
囚心锁ツ
囚心锁ツ 2021-01-02 05:49

My Internet Explorer is set to have an automatic proxy file(so-called PAC) for web access. Is there a way to use this on my Java program, also ?

My below Java code

4条回答
  •  醉话见心
    2021-01-02 06:12

    Wow! I could load Proxy Auto-Config (PAC) file on Java. Please see below codes and package.

    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

提交回复
热议问题