像这样的代码:
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 } } }
SessionManager 不适用于我。最好在 Alamofire中 使用这样的代码:
SessionManager
let request = URLRequest(url: url) request.httpMethod = "GET" //Some configuration Alamofire.request(request).responseJSON { response in }