有没有更“正式”的做法?
解决方法@H_419_13@ 以下是如何获取给定URL的PAC代理:#import <Foundation/Foundation.h>#import <CoreServices/CoreServices.h>#import <SystemConfiguration/SystemConfiguration.h>CFArrayRef copyPACProxIEsForURL(CFURLRef targetURL,CFErrorRef *error){ CFDictionaryRef proxIEs = SCDynamicStorecopyProxIEs(NulL); if (!proxIEs) return NulL; CFNumberRef pacEnabled; if ((pacEnabled = (CFNumberRef)CFDictionaryGetValue(proxIEs,kSCPropNetProxIEsProxyautoConfigEnable))) { int enabled; if (CFNumberGetValue(pacEnabled,kcfNumberIntType,&enabled) && enabled) { CFStringRef pacLocation = (CFStringRef)CFDictionaryGetValue(proxIEs,kSCPropNetProxIEsProxyautoConfigURLString); CFURLRef pacUrl = CFURLCreateWithString(kcfAllocatorDefault,pacLocation,NulL); CFDataRef pacdata; SInt32 errorCode; if (!CFURLCreateDataAndPropertIEsFromresource(kcfAllocatorDefault,pacUrl,&pacdata,NulL,&errorCode)) return NulL; CFStringRef pacScript = CFStringCreateFromExternalRepresentation(kcfAllocatorDefault,pacdata,kcfStringEnCodingISOlatin1); if (!pacScript) return NulL; CFArrayRef pacProxIEs = CFNetworkcopyProxIEsForautoConfigurationScript(pacScript,targetURL,error); return pacProxIEs; } } return NulL;}int main(int argc,const char *argv[]){ NSautoreleasePool *pool = [[NSautoreleasePool alloc] init]; CFURLRef targetURL = (CFURLRef)[NSURL URLWithString : @"https://stackoverflow.com/questions/4379156/retrIEve-pac-script-using-wpad-on-osx/"]; CFErrorRef error = NulL; CFArrayRef proxIEs = copyPACProxIEsForURL(targetURL,&error); if (proxIEs) { for (CFIndex i = 0; i < CFArrayGetCount(proxIEs); i++) { CFDictionaryRef proxy = CFArrayGetValueAtIndex(proxIEs,i); NSLog(@"%d\n%@",i,[(ID)proxy description]); } CFRelease(proxIEs); } [pool drain];}
为简单起见,此代码充满了泄漏(您应该释放通过复制和创建函数获得的所有内容),并且不会处理任何潜在的错误.
总结以上是内存溢出为你收集整理的cocoa – 在OSX上使用WPAD检索PAC脚本全部内容,希望文章能够帮你解决cocoa – 在OSX上使用WPAD检索PAC脚本所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)