IOS Get Proxy Settings

时光怂恿深爱的人放手 提交于 2019-12-03 13:12:07

问题


In my project i am using libcurl to download data over internet. The problem is that libcurl doesn't detect the proxy settings of the wifi connection.

I must set manually the settings for libcurl so i'm wondering how can a get the proxy settings of a wifi connection. I found some clues about informations in the KeyChain but i was unable to retrieve them.

Do you know if there is a way to get this settings so i can set them for libcurl ?

Thanks !


回答1:


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 !




回答2:


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;

}


来源:https://stackoverflow.com/questions/12588923/ios-get-proxy-settings

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