我们可以同时使用系统代理和NSURLSessionConfiguration代理吗?

时间:2022-08-01 19:39:04

looks like only one is taking effect.

看起来只有一个正在生效。

The system proxy is specified in Settings-Wifi-HttpProxy.

系统代理在Settings-Wifi-HttpProxy中指定。

The in-app proxy is specified with:

应用内代理指定为:

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];

NSMutableDictionary *proxyDict= [[NSMutableDictionary alloc] init];
[proxyDict setObject: @1 forKey:@"HTTPSEnable"];

[proxyDict setObject: proxyIP forKey:@"HTTPSProxy"];
[proxyDict setObject: @80 forKey:@"HTTPSPort"];
configuration.connectionProxyDictionary = proxyDict;

how can we use both?

我们怎么能同时使用?

1 个解决方案

#1


0  

As I understand it, the proxy dictionary specified in the session supersedes the system proxy dictionary for all requests made in that session.

据我了解,会话中指定的代理字典取代系统代理字典,以获取该会话中发出的所有请求。

If you want to modify the existing configuration (e.g. to add an HTTPS proxy where only an HTTP proxy currently exists), you would need to start by obtaining the system-provided proxy list using SCDynamicStoreCopyProxies and then modify it.

如果要修改现有配置(例如,添加当前仅存在HTTP代理的HTTPS代理),则需要首先使用SCDynamicStoreCopyProxies获取系统提供的代理列表,然后进行修改。

If you're trying to chain proxies, I'm not aware of any mechanism for doing that other than constructing the proxy URLs manually. I'm fairly certain that there's no system-provided mechanism for doing it, because that isn't the sort of configuration that would typically be used.

如果您正在尝试链接代理,除了手动构建代理URL之外,我不知道有任何其他机制。我很确定没有系统提供的机制来执行此操作,因为这不是通常使用的那种配置。

If your app is doing something unusual, such as using an proxy built into your app that does something special and needs to then forward non-matching requests to the system proxy, then your app's built-in proxy should just re-make the requests in a different session so that any system-provided proxies will be respected.

如果您的应用程序正在做一些不寻常的事情,例如使用内置于您的应用程序中的代理执行特殊操作并需要将非匹配请求转发给系统代理,那么您的应用程序的内置代理应该只是重新发出请求一个不同的会话,以便尊重任何系统提供的代理。

#1


0  

As I understand it, the proxy dictionary specified in the session supersedes the system proxy dictionary for all requests made in that session.

据我了解,会话中指定的代理字典取代系统代理字典,以获取该会话中发出的所有请求。

If you want to modify the existing configuration (e.g. to add an HTTPS proxy where only an HTTP proxy currently exists), you would need to start by obtaining the system-provided proxy list using SCDynamicStoreCopyProxies and then modify it.

如果要修改现有配置(例如,添加当前仅存在HTTP代理的HTTPS代理),则需要首先使用SCDynamicStoreCopyProxies获取系统提供的代理列表,然后进行修改。

If you're trying to chain proxies, I'm not aware of any mechanism for doing that other than constructing the proxy URLs manually. I'm fairly certain that there's no system-provided mechanism for doing it, because that isn't the sort of configuration that would typically be used.

如果您正在尝试链接代理,除了手动构建代理URL之外,我不知道有任何其他机制。我很确定没有系统提供的机制来执行此操作,因为这不是通常使用的那种配置。

If your app is doing something unusual, such as using an proxy built into your app that does something special and needs to then forward non-matching requests to the system proxy, then your app's built-in proxy should just re-make the requests in a different session so that any system-provided proxies will be respected.

如果您的应用程序正在做一些不寻常的事情,例如使用内置于您的应用程序中的代理执行特殊操作并需要将非匹配请求转发给系统代理,那么您的应用程序的内置代理应该只是重新发出请求一个不同的会话,以便尊重任何系统提供的代理。