Hi,
My application needs to make web requests, and I am trying to get it to behave well and automatically detect and use the user's network proxy settings.
My first attempt was to just use CFNetworkCopySystemProxySettings and CFNetworkProxiesForURL. But if I go into the network system preferences and enable a manual proxy (for http for example) or an auto configuration script url, CFNetworkProxiesForURL always returns kCFProxyTypeNone. I assume that this is because the CFProxySupport Reference documents these APIs to 'take advantage of the global proxy configuration settings'. I am not sure where to set these global proxy settings, but they do not appear to be the ones that users would normally configure in their preferences.
I have found a few references suggesting to use the System Configuration APIs to get the proxy dictionary from the dynamic store. So I tried calling SCDynamicStoreCopyProxies to get the dictionary. Now this does appear to return the settings I am looking for, but poses another problem. The sample code I found was looking for the proxy keys (for example "HTTPProxy" in the root of this dictionary. But when I run it, I do not see any of these keys in the root of that dictionary. (I assume these would be the global settings the same as above, and are missing because I do not have any global proxy settings.) But what I do see in this dictionary is the following:
{
__SCOPED__: {
en0: {
HTTPEnable: 1,
HTTPProxy: 127.0.0.1,
HTTPPort: 8888,
...
}
}
}
The proxy settings I am after are scoped under the interface device. That makes sense because each interface device can have its own proxy settings. But my problem is how to determine which interface device will be used for the URL that I will be calling. Are the interfaces under __SCOPED__ returned in any meaningful order? It appears that if I disable an interface, it is not returned in the dictionary. If there are multiple enabled interfaces, are the returned in the order they would be used? If there are global proxy settings, should they be used before the (first?) scoped interface's settings are used, or should it be the other way around?
Any info would be helpful (details are hard to find in any documentation or samples).
Thanks,
Kris