我使用以下代码连接到代理服务器,仅适用于HTTP请求,但不适用于HTTPS。在iOS 9.0中,折旧了 kCFStreamPropertyHTTPSProxyHost 和 kCFStreamPropertyHTTPSProxyPort 。
let myPortInt = 12345;
let myProxyUrlString = "myProxyURL";
let sessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration();
sessionConfiguration.connectionProxyDictionary = [
kCFNetworkProxiesHTTPEnable: true,
kCFNetworkProxiesHTTPPort: myPortInt,
kCFNetworkProxiesHTTPProxy: myProxyUrlString,
]
let url = NSURL(string: endPointUrl)
let postRequest = NSMutableURLRequest(URL: url!, cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 10.0)
let jsonString = bodyString
postRequest.HTTPBody = jsonString
postRequest.HTTPMethod = "POST"
postRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
let session = NSURLSession(configuration: sessionConfiguration)
let task = session.dataTaskWithRequest(postRequest){}
答案 0 :(得分:0)
我找到了向NSURLsession添加HTTPS代理的解决方案
let proxyDict : NSDictionary = ["HTTPEnable": Int(1), "HTTPProxy": myProxyUrlString, "HTTPPort": myPortInt, "HTTPSEnable": Int(1), "HTTPSProxy": myProxyUrlString, "HTTPSPort": myPortInt]
let sessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration();