【问题标题】:Alamofire - error code -999Alamofire - 错误代码 -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 闭包之后,您还缺少括号 ()。此处说明:stackoverflow.com/a/33115013/1433612
  • 嗯,我明白了。让我稍后再更新。顺便谢谢你!

标签: ios swift alamofire


【解决方案1】:

它应该是这样的:

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

【讨论】:

    猜你喜欢
    • 2015-11-18
    • 2017-03-19
    • 2017-03-14
    • 1970-01-01
    • 2016-01-13
    • 1970-01-01
    • 1970-01-01
    • 2013-04-11
    相关资源
    最近更新 更多