Looking over the documentation of NSURLSession
and NSURLSessionConfiguration
, I was under the impression I should configure it with a dictionary like the following:
// Create a dictionary to describe the proxy
NSDictionary *proxyDict = @{
(NSString *)kCFProxyHostNameKey : @"myProxyHost.com",
(NSString *)kCFProxyPortNumberKey : @"12345",
(NSString *)kCFProxyTypeKey : (NSString*)kCFProxyTypeHTTP
};
// Create a configuration that uses the dictionary
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
[configuration setConnectionProxyDictionary:proxyDict];
However, the requests from NSURLSession
created with this configuration connect directly.
If anyone needs the swift version of this:
Swift 3
Based on all previous responses, this works for Swift 4, both HTTP and HTTPS:
proxyHost
should be a hostname and not contain any URL scheme.Swift 3 extension
Usage:
Since several of Jeff's answer keys were deprecated I use this ones
kCFProxyPortNumberKey
value should beInt
notString
It turns out, the dictionary keys you want are the Stream variants, they are the ones that resolve down to "HTTPProxy" and such: