使用alamofire上传文件时如何处理摘要式身份验证?这就是我目前正在做的事情。
Alamofire.upload(.POST, URLString: postUrl,
multipartFormData: {
multipartFormData in
multipartFormData.appendBodyPart(fileURL: fileUrl, name: "filename")},
encodingCompletion: { encodingResult in})
答案 0 :(得分:3)
您需要authenticate
致电upload
中提供的encodingResult
。
Alamofire.upload(
.POST,
URLString: "http://httpbin.org/post",
multipartFormData: { multipartFormData in
multipartFormData.appendBodyPart(fileURL: unicornImageURL, name: "unicorn")
multipartFormData.appendBodyPart(fileURL: rainbowImageURL, name: "rainbow")
},
encodingCompletion: { encodingResult in
switch encodingResult {
case .Success(let upload, _, _):
upload.authenticate(user: "your_user", password: "your_password")
upload.responseJSON { request, response, result in
debugPrint(result)
}
case .Failure(let encodingError):
print(encodingError)
}
}
)