Chức năng cung cấp cho bạn tất cả các thông tin proxy được SCDynamicStoreCopyProxies(), nó có thể được gọi như trong ví dụ dưới đây (khi bạn đã hoàn tất, bạn cũng phải CFRelease
tất cả các đối tượng này, vì chúng ta đều từ CF và không trực tiếp đối tượng Cocoa):
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL);
CFIndex count = CFDictionaryGetCount(proxies);
NSLog(@"Number of keys is %ld", count);
NSDictionary * proxyConfiguration = (NSDictionary*) proxies;
for (id key in proxyConfiguration.keyEnumerator) {
NSLog(@"Pair is %@ -> %@", key, [proxyConfiguration valueForKey: key]);
}
}
return 0;
}
và kết quả sẽ là một cái gì đó như:
2012-11-07 16:33:57.844 network-test[6501:403] Number of keys is 12
2012-11-07 16:33:57.847 network-test[6501:403] Pair is HTTPEnable -> 1
2012-11-07 16:33:57.848 network-test[6501:403] Pair is HTTPSProxy -> 127.0.0.1
2012-11-07 16:33:57.848 network-test[6501:403] Pair is ExceptionsList -> (
"www.google.com"
)
2012-11-07 16:33:57.849 network-test[6501:403] Pair is HTTPSPort -> 8888
2012-11-07 16:33:57.850 network-test[6501:403] Pair is __SCOPED__ -> {
en1 = {
ExceptionsList = (
"www.google.com"
);
FTPPassive = 1;
HTTPEnable = 1;
HTTPPort = 8888;
HTTPProxy = "127.0.0.1";
HTTPSEnable = 1;
HTTPSPort = 8888;
HTTPSProxy = "127.0.0.1";
SOCKSEnable = 1;
SOCKSPort = 8889;
SOCKSProxy = "127.0.0.1";
};
}
2012-11-07 16:33:57.850 network-test[6501:403] Pair is HTTPProxy -> 127.0.0.1
2012-11-07 16:33:57.851 network-test[6501:403] Pair is SOCKSPort -> 8889
2012-11-07 16:33:57.852 network-test[6501:403] Pair is SOCKSProxy -> 127.0.0.1
2012-11-07 16:33:57.852 network-test[6501:403] Pair is HTTPSEnable -> 1
2012-11-07 16:33:57.853 network-test[6501:403] Pair is SOCKSEnable -> 1
2012-11-07 16:33:57.853 network-test[6501:403] Pair is HTTPPort -> 8888
2012-11-07 16:33:57.854 network-test[6501:403] Pair is FTPPassive -> 1
Nguồn
2012-11-07 22:04:07
Hãy kiểm tra liên kết sau đây cũng: http://stackoverflow.com/questions/4379156/retrieve-pac-script-using-wpad-on-osx Kính trọng, Anand Choubey –