小编use*_*902的帖子

我该如何抑制/绕过代理警报

我在我的代码中使用代理并获得身份验证挑战.但在"didReceiveChallenge"被调用之前,我正在获得警报,如下图所示在此输入图像描述.如果我在警报上单击"取消",则调用"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 …
Run Code Online (Sandbox Code Playgroud)

proxy-server ios nsurlsession swift

5
推荐指数
0
解决办法
135
查看次数

标签 统计

ios ×1

nsurlsession ×1

proxy-server ×1

swift ×1