小编典典

Alamofire:完成错误-代码:-1001

swift

像这样的代码:

import Foundation
import Alamofire
struct Request {
var alamoFireManager : SessionManager?
init() {
    let configuration = URLSessionConfiguration.default
            configuration.timeoutIntervalForRequest = 20
    configuration.requestCachePolicy = .useProtocolCachePolicy
            alamoFireManager = Alamofire.SessionManager(configuration: configuration)
}

func sendRequest() {

    alamoFireManager?.request(url,method: method, parameters: body, encoding: JSONEncoding.default,headers: headers).responseJSON { response in

    }
}
}

阅读 319

收藏
2020-07-07

共1个答案

小编典典

SessionManager 不适用于我。最好在 Alamofire中 使用这样的代码:

let request = URLRequest(url: url)
request.httpMethod = "GET"
//Some configuration


Alamofire.request(request).responseJSON {
                response in

}
2020-07-07