Java 的 ProxySelector 是否不适用于自动代理配置脚本? [英] Does Java's ProxySelector not work with automatic proxy configuration scripts?

查看:24
本文介绍了Java 的 ProxySelector 是否不适用于自动代理配置脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的 Java 程序使用系统的代理配置.因此,我使用了在很多地方找到的代码,例如这个答案,来设置 java.net.useSystemProxies 为 true 并调用 ProxySelector.getDefault().select(...) 来发现我想要访问的特定主机的代理.当我在 Internet 属性中配置了单个显式代理服务器时,这可以正常工作.但是如果我设置了使用自动配置脚本",它总是返回直接的代理".

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.useSystemProxies to true and call ProxySelector.getDefault().select(...) to discover the proxy for the particular host I want to reach. This works fine when I've configured a single explicit proxy server in Internet Properties. But if I have set "Use automatic configuration script", it always returns the DIRECT "proxy".

我知道脚本可以工作,因为我的浏览器可以访问它返回代理服务器的主机,而没有脚本集,它就不能.我什至尝试将脚本简化为最基本的要素:

I know that the script works, as my browser can access the hosts for which it returns a proxy server, and without the script set, it can't. I even tried simplifying the script to its barest essentials:

function FindProxyForURL(url, host)
{
    return "PROXY my.proxy.mydomain:3128";
}

它在我的浏览器中工作,但 ProxySelector.getDefault().select(...) 仍然只返回 DIRECT.

and it works in my browser, but ProxySelector.getDefault().select(...) still returns only DIRECT.

我错过了什么吗?(这是在 Java 1.6 和 Windows 7 上,应该重要.)

Am I missing something? (This is on Java 1.6 & Windows 7, should it matter.)

推荐答案

不,Java ProxySelector 不读取 代理自动配置 (PAC) 文件.

No, the Java ProxySelector does not read Proxy Auto-Config (PAC) files.

但是,正如 Brian de Alwis 所建议的 作为对我类似问题的回答,Proxy Vole 库似乎提供了这种支持/功能.

However, as suggested by Brian de Alwis as an answer to my similar question, the Proxy Vole library appears to provide that support/capability.

为您提供开箱即用的网络连接 Java您可以使用 Proxy - Vole 库的应用程序.它提供了一些自动检测当前代理设置的策略.有许多可配置的策略可供选择.目前代理 -Vole 支持以下代理检测策略.

To provide network connectivity out of the box for you Java application you can use the Proxy - Vole library. It provides some strategies for autodetecting the current proxy settings. There are many configureable strategies to choose from. At the moment Proxy - Vole supports the following proxy detection strategies.

  • 读取平台设置(支持:Windows、KDE、Gnome、OSX)
  • 读取浏览器设置(支持:Firefox 3.x、Internet Explorer;Chrome 和 Webkit 使用平台设置)
  • 读取环境变量(Linux/Unix 服务器系统上经常使用的变量)
  • 使用 WPAD/PAC 的自动检测脚本(并非支持所有变体)
  • Read platform settings (Supports: Windows, KDE, Gnome, OSX)
  • Read browser setting (Supports: Firefox 3.x, Internet Explorer; Chrome and Webkit use the platform settings)
  • Read environment variables (often used variables on Linux / Unix server systems)
  • Autodetection script by using WPAD/PAC (Not all variations supported)

这篇关于Java 的 ProxySelector 是否不适用于自动代理配置脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆