Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is how to get PAC proxies for a given URL:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import &lt;CoreServices/CoreServices.h&gt; #import &lt;SystemConfiguration/SystemConfiguration.h&gt; 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, &amp;enabled) &amp;&amp; enabled) { CFStringRef pacLocation = (CFStringRef)CFDictionaryGetValue(proxies, kSCPropNetProxiesProxyAutoConfigURLString); CFURLRef pacUrl = CFURLCreateWithString(kCFAllocatorDefault, pacLocation, NULL); CFDataRef pacData; SInt32 errorCode; if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, pacUrl, &amp;pacData, NULL, NULL, &amp;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 : @"http://stackoverflow.com/questions/4379156/retrieve-pac-script-using-wpad-on-osx/"]; CFErrorRef error = NULL; CFArrayRef proxies = CopyPACProxiesForURL(targetURL, &amp;error); if (proxies) { for (CFIndex i = 0; i &lt; CFArrayGetCount(proxies); i++) { CFDictionaryRef proxy = CFArrayGetValueAtIndex(proxies, i); NSLog(@"%d\n%@", i, [(id)proxy description]); } CFRelease(proxies); } [pool drain]; } </code></pre> <p>For the sake of simplicity, this code is full of leaks (you should release everything you got through <em>Copy</em> and <em>Create</em> functions) and does not handle any potential error.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload