How can I suppress or bypass proxy alert

I use a proxy server in my code and get authentication. But before the “didReceiveChallenge” receives the call, I get a warning as shown below. enter image description here . If I click cancel in the warning, what caused the didReceiveChallenge.

let url = NSURL(string: "http://www.google.com") let request = NSURLRequest(URL: url!) let config = NSURLSessionConfiguration.ephemeralSessionConfiguration() let proxyDict:[String:AnyObject] = [kCFNetworkProxiesHTTPEnable as String: true, hostKey as String:proxy_server, portKey as String: proxy_port, userNameKey as String:userName, passwordKey as String:password] config.connectionProxyDictionary = proxyDict as [NSObject : AnyObject] let session = NSURLSession(configuration: config, delegate: self, delegateQueue: NSOperationQueue.mainQueue()) let task = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) in print(data) print(error) print(response) }); task.resume() func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void) { let credential = NSURLCredential(user:user, password:password, persistence: .ForSession) completionHandler(NSURLSessionAuthChallengeDisposition.UseCredential,credential) } 

How can I suppress / bypass the alert that comes ?. Any help is appreciated.

+5
source share

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


All Articles