Wie füge ich einen HTTPS-Proxy zu NSURLSession in SWIFT 3 hinzu?
Ich habe den folgenden Code für die Verbindung zum Proxy-Server verwendet und eignet sich hervorragend nur für HTTP-Anforderungen, nicht jedoch für HTTPS. In iOS 9.0 wurde kCFStreamPropertyHTTPSProxyHost und kCFStreamPropertyHTTPSProxyPort werden abgeschrieben.
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){}