JAVA - 从 url 请求代理
我有一个疑问想澄清一下。 我正在用 java 编程,并尝试访问受代理保护的 URL。我想知道是否可以通过 URL 知道代理设置是什么,然后通过此设置通过代理访问 URL。问候,
我想我没有解释清楚。
在我们的浏览器选项->局域网设置中,我们可以将代理服务器以及端口和主机放在那里(并且可以使用以下代码访问此信息:)
' System.setProperty("java.net.useSystemProxies", "真的”); System.out.println("检测代理");列表 pl = ProxySelector.getDefault().select(new URI("http://google.pt/")); for (代理 p : pl) System.out.println(p);代理 p = null; if (pl.size() > 0) //使用第一个 p = pl.get(0); System.out.println(p.address()); System.out.println("完成"); '
但我的问题是当我使用“自动配置脚本”并放置脚本的路径时。在这种情况下,a 无法访问代理信息。我尝试在 C# 中执行此操作,并使用“WebRequest.GetSystemWebProxy()”并且它有效。
我需要做什么才能在java中工作?
I have a doubt that I would like to clarify.
I am programming in java and am trying to access a URL that has protected by proxy. I wonder if it was possible through URL know what are the proxy settings, then with this settings access to the URL through proxy.Regards
I think i don't explain myself clear.
In our browser options->lan setings, we can put there the proxy server with the port and host(and this a can access to this information with this code:)
' System.setProperty("java.net.useSystemProxies", "true"); System.out.println("detecting proxies"); List pl = ProxySelector.getDefault().select(new URI("http://google.pt/")); for (Proxy p : pl) System.out.println(p); Proxy p = null; if (pl.size() > 0) //uses first one p = pl.get(0); System.out.println(p.address()); System.out.println("Done"); '
But my problem is when i use the "automatic configuration script" and a put the path of the script. In this case a can't access to the proxy information. I try to do this in C# and i use the ' WebRequest.GetSystemWebProxy() ' and it works.
What i need to do to work in java?
您无法从 URL 获取代理,但当您知道 URL 时,可以从自动配置脚本 (PAC) 获取代理
这里是一个解析/验证此类脚本的网站
库来执行此操作(python)
博客文章如何在 Java 中解析 PAC
You cannot get proxy from an url, but you can get it from automatic configuration script (PAC) when you know the URL
Here is a website that parses/validates such scripts
Library to do so (python)
Blog post how to parse PAC in Java