Alamofire - 错误代码 -999

Posted

技术标签:

【中文标题】Alamofire - 错误代码 -999【英文标题】:Alamofire - error code -999 【发布时间】:2017-10-12 19:33:17 【问题描述】:

我写的

class Property
    ...
    static var alamofireManager: SessionManager
        let sessionConfiguration = URLSessionConfiguration.default
        sessionConfiguration.timeoutIntervalForRequest = 10
        return Alamofire.SessionManager(configuration: sessionConfiguration)
    
    ...

供多个类的函数使用。

但是,当我使用它时:

Property.alamofireManager.request(loginURL).validate(contentType: ["application/json"]).responseJSON response in
....

我收到错误提示:

任务 . 以错误结束 - 代码:-999

我知道如果我只使用 Alamofire 就可以。有谁知道为什么这不起作用?

谢谢!

【问题讨论】:

我的猜测是因为与 Alamofire 的默认 SessionManager 不同,您没有创建任何标题。因此缺少重要信息,例如Accept-EncodingAccept-Language 在 var 闭包之后,您还缺少括号 ()。此处说明:***.com/a/33115013/1433612 嗯,我明白了。让我稍后再更新。顺便谢谢你! 试试这个***.com/a/52868844/5032981 【参考方案1】:

它应该是这样的:

static let alamofireManager: SessionManager = 
    let sessionConfiguration = URLSessionConfiguration.default
    sessionConfiguration.timeoutIntervalForRequest = 10
    return Alamofire.SessionManager(configuration: sessionConfiguration)
()

【讨论】:

以上是关于Alamofire - 错误代码 -999的主要内容,如果未能解决你的问题,请参考以下文章