本文介绍了Alamofire:responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.inputDataNilOrZeroLength)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过alamofire上传数据,包括图像。但它会返回
I am trying to upload data through alamofire including images. But it returns
-
而我的代码是,
-- and my code is ,
Alamofire.upload(multipartFormData: { (multipartFormData) in
multipartFormData.append((userid?.data(using: String.Encoding.utf8))!, withName: "user_id")
multipartFormData.append((self.addUserBtnTag?.description.data(using: String.Encoding.utf8))!, withName: "slot")
}, to: urlString, method: .post, encodingCompletion: { (result) in
switch result {
case .success(let upload, _, _):
upload.responseJSON { response in
print(response.result)
print("Response : ", response)
if response.result.isSuccess
{
let JSON = response.result.value as? NSDictionary
print("EditJSON : ", JSON!)
}
}
case .failure(let encodingError):
print(encodingError)
}
})
但是实际上我通过alamofire传递了十多个参数。
But actually I am passing more than ten parameters through alamofire.
推荐答案
只需将 responseJSON
更改为 responseString
Alamofire.upload(multipartFormData: { (multipartFormData) in
multipartFormData.append((userid?.data(using: String.Encoding.utf8))!, withName: "user_id")
multipartFormData.append((self.addUserBtnTag?.description.data(using: String.Encoding.utf8))!, withName: "slot")
}, to: urlString, method: .post, encodingCompletion: { (result) in
switch result {
case .success(let upload, _, _):
upload.responseString { response in
print(response.result)
print("Response : ", response)
if response.result.isSuccess
{
let JSON = response.result.value as? NSDictionary
print("EditJSON : ", JSON!)
}
}
case .failure(let encodingError):
print(encodingError)
}
})
这篇关于Alamofire:responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.inputDataNilOrZeroLength)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!