IOS获取代理设置 [英] IOS Get Proxy Settings
问题描述
在我的项目中,我使用libcurl通过互联网下载数据。问题是libcurl没有检测到wifi连接的代理设置。
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.
我必须手动设置libcurl的设置所以我想知道如何获得wifi连接的代理设置。我在KeyChain中找到了一些关于信息的线索,但我无法检索它们。
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.
你知道是否有办法获得这个设置所以我可以设置它们libcurl?
Do you know if there is a way to get this settings so i can set them for libcurl ?
谢谢!
推荐答案
我找到了回复!
使用这段代码似乎有效:
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 !
这篇关于IOS获取代理设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!