问题
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