我正在嘗試使用Swift 3.0,iOS 10和xCode 8的Alamofire(最新版本)。代碼寫在下面,我不斷收到同樣的問題。請幫助,將在此感謝任何事情。Swift 3.0 Alamofire 4.0 - 域名= NSURLErrorDomain代碼= -999「取消」
private class func getDefaultHeaders() -> HTTPHeaders {
let headers: HTTPHeaders = [
"Connection" : "keep-alive",
"token" : "0781d3957fd8da6ee35c4e3124d974a2999925274771234",
"nonce" : "9b2436331ed908bb2f399568d2adbc4e",
"uuid" : "uuid",
"latitude" : "43.656781",
"longitude" : "-79.380823",
"Content-Type" : "application/json",
"userTypeId" : "1",
"userAgent" : "UserAgent",
"Content-Length" : "0",
"Host" : "localhost:8080",
"User-Agent" : "iOS Example/1.0 (com.alamofire.iOS-Example; build:1; iOS 10.0.0) Alamofire/4.0.0"
]
return headers
}
func generateCustomSession() -> SessionManager {
let headers = ServicesController.getDefaultHeaders()
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = headers
let manager: SessionManager = SessionManager(configuration: configuration)
return manager
}
func post(url: String, success:@escaping (JSON) -> Void, failure:@escaping (Error) -> Void) {
generateCustomSession().request(
url,
method: .post,
encoding: JSONEncoding.default)
.validate(statusCode: 200..<300)
.downloadProgress { (progress) -> Void in
print("download progress: \(progress.fractionCompleted)")
}
.responseJSON { (response) -> Void in
if #available(iOS 10.0, *) {
print(response.metrics)
}
debugPrint(response)
if response.result.isSuccess {
let resJson = JSON(response.result.value!)
success(resJson)
}
if response.result.isFailure {
let error : Error = response.result.error!
failure(error)
}
}
}
除了告訴服務器修復你的證書問題之外,不應該有辦法解決這個問題。 – ahmad