error: inputDataNilOrZeroLength in Swift with Alamofire
error: inputDataNilOrZeroLength in Swift with Alamofire
responseSerializationFailed(原因:Alamofire.AFError.ResponseSerializationFailureReason.inputDataNilOrZeroLength)
这是什么意思?
struct URLService {
static var language = LocalizationService.shared.language.userSymbol.uppercased()
static let baseUrl = "http://192.168.9.42:5080"
static func checkLogin(login: String, password: String) {
let parametrs: Parameters = [
"language": "RU",
"password": "password",
"username": "login"
]
let url = "\(URLService.baseUrl)/someURL"
let authRequest = AF.request(url,
method: .post,
parameters: parametrs,
encoding: URLEncoding(destination: .queryString))
authRequest.responseData { (response) in
switch(response.result) {
case .success(_):
print("\(response) check response")
case .failure(let error):
print("\(error) check error")
}
}
}
}
你会帮助我,如果告诉我这个错误的其他案例和你的修复。
对我来说是对的:
let authRequest = AF.request(url,
method: .post,
parameters: parameters,
encoding: JSONEncoding.default)
authRequest.responseString { response in
switch response.result {
case .success(let value):
print("succes")
case .failure(let error):
print("Error while querying database: \(String(describing: error))")
}
}
JSONEncoding + responseString(为了更方便)
responseSerializationFailed(原因:Alamofire.AFError.ResponseSerializationFailureReason.inputDataNilOrZeroLength)
这是什么意思?
struct URLService {
static var language = LocalizationService.shared.language.userSymbol.uppercased()
static let baseUrl = "http://192.168.9.42:5080"
static func checkLogin(login: String, password: String) {
let parametrs: Parameters = [
"language": "RU",
"password": "password",
"username": "login"
]
let url = "\(URLService.baseUrl)/someURL"
let authRequest = AF.request(url,
method: .post,
parameters: parametrs,
encoding: URLEncoding(destination: .queryString))
authRequest.responseData { (response) in
switch(response.result) {
case .success(_):
print("\(response) check response")
case .failure(let error):
print("\(error) check error")
}
}
}
}
你会帮助我,如果告诉我这个错误的其他案例和你的修复。
对我来说是对的:
let authRequest = AF.request(url,
method: .post,
parameters: parameters,
encoding: JSONEncoding.default)
authRequest.responseString { response in
switch response.result {
case .success(let value):
print("succes")
case .failure(let error):
print("Error while querying database: \(String(describing: error))")
}
}
JSONEncoding + responseString(为了更方便)