SCNetworkReachability 是否尊重 HTTP 代理设置? [英] Does SCNetworkReachability respect HTTP proxy settings?

查看:57
本文介绍了SCNetworkReachability 是否尊重 HTTP 代理设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

恐怕答案是否定的,但我希望有人可以提供明确的答案,因为当前的 iOS SDK 文档中没有记录.

I'm afraid the answer to this is No, but I'm hoping someone can provide a definitive answer as it is not documented in the current iOS SDK documentation.

我们发现 NSURLConnection 能够通过 HTTP 代理连接到 https://mysite.com但是,由于在这种情况下本地 DNS 的设置方式,mysite.com 的 DNS 查找将失败.在这种情况下,似乎 SCNetworkReachability 正在尝试对 mysite.com 执行 DNS 查找并失败.同时,NSURLConnection 可以连接.

We're seeing a case where NSURLConnection is able to connect to https://mysite.com via an HTTP proxy but, because of the way the local DNS is setup in this case, DNS lookups for mysite.com will fail. In this case, it appears that SCNetworkReachability is trying to perform a DNS lookup for mysite.com and failing. Meanwhile, NSURLConnection is able to connect.

我们已将 Apple Reachability 示例代码合并到我们的应用中,并通过 mysite.com 调用 SCNetworkReachabilityCreateWithName.

We have incorporated the Apple Reachability sample code into our app and are calling SCNetworkReachabilityCreateWithName with mysite.com.

推荐答案

我无法提供明确的答案,但我可以提供更多的经验证据和一些理由来证明答案是否定的.我有一个应用程序,它使用 SCNetworkReachabilityGetFlags 来检查特定主机是否可访问(例如:www.mysite.com).根据可达性检查,它然后使用 [NSMutableData dataWithContentsOfURL:] 下载数据.

I can't provide a definitive answer, but I can provide more empirical evidence, and some justification, that the answer is NO. I have an app that uses SCNetworkReachabilityGetFlags to check whether a particular host is reachable (e.g.: www.mysite.com). Depending on that reachability check, it then uses [NSMutableData dataWithContentsOfURL:] to download the data.

该应用程序一直运行良好,但最近我一直在通过公司 HTTP 代理进行网络访问的工作中进行一些编码.在 iOS 模拟器(使用我的 Mac 上配置的代理设置)中运行应用程序时,可达性检查失败.一开始我以为 iOS 模拟器可能没有使用 Mac 的代理设置,但模拟器中的 Mobile Safari 运行良好.所以我删除了我的应用程序中的可达性检查,并且对 [NSMutableData dataWithContentsOfURL:] 的调用工作正常.这似乎表明 SCNetworkReachability 不遵守代理设置.

The app has always worked fine, but recently I've been doing some coding at work where network access is via the corporate HTTP proxy. When running the app in the iOS Simulator (which uses the proxy settings configured on my Mac) the reachability check fails. At first I thought that perhaps the iOS Simulator wasn't using the Mac's proxy settings, but Mobile Safari in the simulator worked fine. So I removed the reachability check in my app and the call to [NSMutableData dataWithContentsOfURL:] worked fine. This would appear to indicate that SCNetworkReachability does not respect the proxy settings.

考虑一下,如果您将 SCNetworkReachability 视为在 TCP/IP 级别运行,而不是在 HTTP 级别运行,这可能是正确的行为,就像 ping google.com 在位于公司防火墙后面的 Mac/PC 也不起作用.HTTP 代理(顾名思义)用于 HTTP 协议,而不是整个 TCP/IP 堆栈.

Having thought about it, this is probably the correct behaviour if you view SCNetworkReachability as running at the TCP/IP level, not at the HTTP level, in the same way that ping google.com on a Mac/PC behind a corporate firewall doesn't work either. The HTTP proxy (as the name implies) is for the HTTP protocol, not the whole TCP/IP stack.

阅读了有关可达性问题的答案后,我倾向于将可达性检查完全归类.尽管到目前为止它只是模拟器中的一个问题,但在其他情况下(例如需要身份验证的公共 WiFi 热点)可能会出现问题.

Having read the answers to this question on Reachability I'm inclined to bin my reachability check altogether. Even though it's only been a problem in the simulator until now, it could be problematic in other situations (e.g. public WiFi hotspot that requires authentication).

这篇关于SCNetworkReachability 是否尊重 HTTP 代理设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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