How to add HTTPS proxy to NSURLSession in SWIFT 3

I used the following code to connect to a proxy server and works fine only for HTTP requests, but not for HTTPS. IOS 9.0 depreciates kCFStreamPropertyHTTPSProxyHost and 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){} 
+3
source share
1 answer

I found a solution to add HTTPS proxies to NSURLsession

  let proxyDict : NSDictionary = ["HTTPEnable": Int(1), "HTTPProxy": myProxyUrlString, "HTTPPort": myPortInt, "HTTPSEnable": Int(1), "HTTPSProxy": myProxyUrlString, "HTTPSPort": myPortInt] let sessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration(); 
+1
source

Source: https://habr.com/ru/post/946225/


All Articles