QNetworkProxyFactory

概要

虚函数

静态函数

详细描述

PySide.QtNetwork.QNetworkProxyFactory class provides fine-grained proxy selection.

PySide.QtNetwork.QNetworkProxyFactory is an extension to PySide.QtNetwork.QNetworkProxy ,允许应用程序对使用哪种代理服务器有更细粒度控制 (从属套接字请求代理)。例如,这允许应用程序根据协议或目标主机名应用不同设置。

PySide.QtNetwork.QNetworkProxyFactory can be set globally for an application, in which case it will override any global proxies set with QNetworkProxy.setApplicationProxy() . If set globally, any sockets created with Qt will query the factory to determine the proxy to be used.

也可以在支持多个连接的某些框架中设置工厂,譬如 PySide.QtNetwork.QNetworkAccessManager 。当在这种对象上设置时,将只查询由该框架创建的套接字的工厂。

系统代理

可以把工厂配置为使用系统代理的设置。调用 PySide.QtNetwork.QNetworkProxyFactory.setUseSystemConfiguration() function with true to enable this behavior, or false to disable it.

同样,可以使用工厂以直接查询系统代理通过调用其 PySide.QtNetwork.QNetworkProxyFactory.systemProxyForQuery() 函数。

警告

从属用户系统配置,在某些平台使用的系统代理特征可能会受到限制。 PySide.QtNetwork.QNetworkProxyFactory.systemProxyForQuery() documentation contains a list of these limitations for those platforms that are affected.

class PySide.QtNetwork. QNetworkProxyFactory

创建 PySide.QtNetwork.QNetworkProxyFactory 对象。

Since PySide.QtNetwork.QNetworkProxyFactory is an abstract class, you cannot create objects of type PySide.QtNetwork.QNetworkProxyFactory directly.

static PySide.QtNetwork.QNetworkProxyFactory. proxyForQuery ( query )
参数: query PySide.QtNetwork.QNetworkProxyQuery
返回类型:

此函数接受查询请求 query ,审查套接字或请求类型的细节,并返回列表为 PySide.QtNetwork.QNetworkProxy 对象 (按首选次序指示要使用的代理服务器)。

PySide.QtNetwork.QNetworkProxyFactory. queryProxy ( [ query=QNetworkProxyQuery() ] )
参数: query PySide.QtNetwork.QNetworkProxyQuery
返回类型:

此函数接受查询请求 query ,审查套接字或请求类型的细节,并返回列表为 PySide.QtNetwork.QNetworkProxy 对象 (按首选次序指示要使用的代理服务器)。

当重实现此类时,小心至少要返回一元素。

若无法确定更好的代理替代方案,使用 QNetworkProxy.DefaultProxy ,它告诉代码查询代理以使用更高替代。例如,若把此工厂设置给 PySide.QtNetwork.QNetworkAccessManager 对象,DefaultProxy 将告诉它以查询应用程序级代理设置。

若此工厂被设置为应用程序代理工厂,DefaultProxy 和 Noproxy 将拥有相同含义。

static PySide.QtNetwork.QNetworkProxyFactory. setApplicationProxyFactory ( factory )
参数: factory PySide.QtNetwork.QNetworkProxyFactory

把应用程序范围代理工厂设为 factory 。此函数将拥有该对象的所有权,并在必要时删除它。

应用程序范围代理被用作最后手段,当所有其他代理选择请求返回 QNetworkProxy.DefaultProxy 。例如, PySide.QtNetwork.QTcpSocket objects can have a proxy set with QTcpSocket::setProxy, but if none is set, the proxy factory class set with this function will be queried.

If you set a proxy factory with this function, any application level proxies set with QNetworkProxy::setApplicationProxy will be overridden.

static PySide.QtNetwork.QNetworkProxyFactory. setUseSystemConfiguration ( enable )
参数: enable PySide.QtCore.bool

启用特定平台代理设置的使用,且只使用那些。见 PySide.QtNetwork.QNetworkProxyFactory.systemProxyForQuery() 了解更多信息。

Internally, this method (when called with enable set to true) sets an application-wide proxy factory. For this reason, this method is mutually exclusive with PySide.QtNetwork.QNetworkProxyFactory.setApplicationProxyFactory() : calling PySide.QtNetwork.QNetworkProxyFactory.setApplicationProxyFactory() overrides the use of the system-wide proxy, and calling PySide.QtNetwork.QNetworkProxyFactory.setUseSystemConfiguration() overrides any application proxy or proxy factory that was previously set.

注意

PySide.QtNetwork.QNetworkProxyFactory.systemProxyForQuery() documentation for a list of limitations related to the use of system proxies.

static PySide.QtNetwork.QNetworkProxyFactory. systemProxyForQuery ( [ query=QNetworkProxyQuery() ] )
参数: query PySide.QtNetwork.QNetworkProxyQuery
返回类型:

此函数接受查询请求 query ,审查套接字或请求类型的细节,并返回列表为 PySide.QtNetwork.QNetworkProxy 对象 (按首选次序指示要使用的代理服务器)。

此函数可用于确定特定于平台的代理设置。此函数将使用由操作系统提供的库来确定给定连接的代理,若存在这样的库。若不存在,此函数将仅仅返回 PySide.QtNetwork.QNetworkProxy of type QNetworkProxy.NoProxy .

在 Windows,此函数将使用 WinHTTP DLL 功能。尽管其名称,Microsoft 建议所有要求网络连接的应用程序都使用它,而不仅仅是 HTTP。这会考虑采用 proxycfg.exe 工具在注册表中设置的代理设置。若找不到这些设置,此函数将尝试获得 Internet Explorer 设置并使用它们。

On MacOS X, this function will obtain the proxy settings using the SystemConfiguration framework from Apple. It will apply the FTP, HTTP and HTTPS proxy configurations for queries that contain the protocol tag “ftp”, “http” and “https”, respectively. If the SOCKS proxy is enabled in that configuration, this function will use the SOCKS server for all queries. If SOCKS isn't enabled, it will use the HTTPS proxy for all TcpSocket and UrlRequest queries.

On BlackBerry, this function obtains proxy settings for the default configuration using system configuration. The type will be set based on protocol tag “http”, “https”, “ftp”, respectively. By default, it assumes http type. Proxy username and password are also set during the query using system configuration.

On other systems, this function will pick up proxy settings from the “http_proxy” environment variable. This variable must be a URL using one of the following schemes: “http”, “socks5” or “socks5h”.

局限性

这些是此函数当前版本的局限性。未来版本的 Qt 可能消除这里列出的某些局限性。

  • On MacOS X, this function will ignore the Proxy Auto Configuration settings, since it cannot execute the associated ECMAScript code.

  • 在 Windows 平台,此函数可能需要几秒钟来执行 (取决于用户的系统配置)。

    UnknownCommandOn BlackBerry, only UrlRequest and TcpSocket queries are supported. SOCKS is not supported. The proxy credentials are only retrieved for the default configuration.