在 NSStream 中使用系统代理
我正在使用 [NSStream getStreamsToHost:port:inputStream:outputStream:] 创建一个到 Web 服务器的新流,以动态传输生成的数据。我将如何设置 NSStream
以像 NSURLConnection
一样使用系统 HTTP 代理?我找不到任何有关如何查找系统代理的信息,到目前为止我所发现的只是如何针对流设置已知的 SOCKS 代理。
谢谢, J
I'm using [NSStream getStreamsToHost:port:inputStream:outputStream:]
to create a new stream to a web server to stream generated data on the fly. How would I go about setting up the NSStream
to use the system HTTP proxy like NSURLConnection
does? I can't find any info on how to lookup the system proxy, so far all I've discovered is how to setup a known SOCKS proxy against the stream.
Thanks,
J
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
免责声明:
NSStream
/CF(Read|Write)StreamRef
API 的新手。解决这个问题后,解决方法似乎是使用 SystemConfiguration 框架,即函数 SCDynamicStoreCopyProxies。
此函数返回一个
CFDictionaryRef
,然后可以将其设置为流的kCFStreamPropertyHTTPProxy
属性(任何其他代理类型都应使用协议的等效密钥来工作)。我还不知道是否必须在 CoreFoundation 级别设置此属性,或者是否也可以使用
-[NSStream setProperty:forKey:]
— 我强烈认为是后者,但再说一次:我今天或多或少开始认真研究这些 API...无论如何,有一个名为 “导航防火墙” 涵盖了这些内容在 Apple 的 CFNetworking 编程指南 中,其中更详细地描述了这一点。
更新
如果有人仍然对此感兴趣,有一个 API 我整个周末都没有找到。
在 iOS 上,
SCDynamicStore
API(在我发布的链接中引用)不存在。然而,另一个 API 自 iOS 2.0 起就已存在,并自 10.6 起就出现在 OS X 上:CFProxySupport
尽管
CFProxySupport
是CFNetwork 框架,在《CFNetwork 编程指南》的任何地方都没有提到它——这很遗憾,因为它简单易用。向 Apple 文档提交了一个错误 (rdar://problem/10491759)
Disclaimer:
NSStream
/CF(Read|Write)StreamRef
APIs.With that out of the way, the way to go appears to be using the
SystemConfiguration
-framework — namely the functionSCDynamicStoreCopyProxies
.This function returns a
CFDictionaryRef
, which can then be set as the stream'skCFStreamPropertyHTTPProxy
-property (any other proxy type should work by using the protocol's equivalent key).I don't know yet, whether it is imperative to set this property on the CoreFoundation-level or if using
-[NSStream setProperty:forKey:]
is possible, as well — I strongly assume the latter, but again: I more or less started seriously looking into these APIs today…Anyway, there's a section called "Navigating Firewalls" covering this stuff in Apple's CFNetworking Programming Guide—which describes this more detailed.
Update
In case anyone is still interested in this, there's an API which I managed to not find, the whole weekend.
On iOS, the
SCDynamicStore
APIs (which are referred to in the link I posted) do not exist. There is, however, another API which has been around since iOS 2.0 and is present on OS X since 10.6:CFProxySupport
Although
CFProxySupport
is part of theCFNetwork
framework, it isn't mentioned anywhere in the "CFNetwork Programming Guide" — which is a shame because it's simple and pleasant to use.Filed a bug with Apple's docs (rdar://problem/10491759)