Alamofire 4 swift 3 - https凭据

时间:2016-09-23 07:11:55

标签: swift https alamofire credentials

我想通过https在服务器上使用用户和密码,并在Swift 3上使用Alamofire 4获取一些JSON Feed

 let urlRequest = URLRequest(url: URL(string: "https://myserver.com:123/apps/?cmd=getjson")!)
    let urlString = urlRequest.url?.absoluteString

    let user = "myuser"
    let passwort = "one password"

    let credential = URLCredential(user: user, password: passwort, persistence: .forSession)

     let configuration =  URLSessionConfiguration.default
    configuration.requestCachePolicy = NSURLRequest.CachePolicy.reloadIgnoringLocalAndRemoteCacheData
    configuration.timeoutIntervalForResource = 15
    let almomanager = SessionManager(configuration:configuration)

    almomanager.request( urlString! )
        .authenticate(usingCredential: credential)
        .responseJSON { response in
            debugPrint(response)
    }

但是

失败了
Error Domain=NSURLErrorDomain Code=-999 "cancelled" 

使用较旧版本的Alamofire和Swift,它运行正常! 我的错误在哪里?

0 个答案:

没有答案