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
Disclaimer:
- I have not tried this myself, yet.
- I am a novice to using the
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 function SCDynamicStoreCopyProxies
.
This function returns a CFDictionaryRef
, which can then be set as the stream's kCFStreamPropertyHTTPProxy
-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 the CFNetwork
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)
精彩评论