3
다음 코드를 사용하여 프록시 서버에 연결했으며 HTTP 요청만으로는 작동하지만 HTTPS에는 적합하지 않습니다. iOS 9.0에서 kCFStreamPropertyHTTPSProxyHost 및 kCFStreamPropertyHTTPSProxyPort은 가치가 하락합니다.SWIFT 3의 NSURLSession에 HTTPS 프록시를 추가하는 방법
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){}