IOS Get Proxy Settings

梦想与她 提交于 2019-12-03 04:13:31

I found the response !

Using this bit of code seems to work :

std::string getProxyName()
{
    CFDictionaryRef dicRef = CFNetworkCopySystemProxySettings();
    const CFStringRef proxyCFstr = (const CFStringRef)CFDictionaryGetValue(dicRef, (const void*)kCFNetworkProxiesHTTPProxy);
    char buffer[4096];
    memset(buffer, 0, 4096);
    if (CFStringGetCString(proxyCFstr, buffer, 4096, kCFStringEncodingUTF8))
    {
        return std::string(buffer);
    }
    return "";
}


int CDownloadThread::getProxyPort()
{
    CFDictionaryRef dicRef = CFNetworkCopySystemProxySettings();
    const CFNumberRef portCFnum = (const CFNumberRef)CFDictionaryGetValue(dicRef, (const void*)kCFNetworkProxiesHTTPPort);

    SInt32 port;
    if (CFNumberGetValue(portCFnum, kCFNumberSInt32Type, &port))
    {
        return port;
    }
    return -1;
}

I haven't try with automatic proxy configuration yet but i hope it's working !

Vishal Adatia

It will give IP address as String.

(NSString *)proxyName 
{

    CFDictionaryRef dicRef = CFNetworkCopySystemProxySettings();

    const CFStringRef proxyCFstr = (const CFStringRef)CFDictionaryGetValue(dicRef,
                                   (const void*)kCFNetworkProxiesHTTPProxy);

    return  (__bridge NSString *)proxyCFstr;

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!