Alamofire 4.0上传MultipartFormData标头 [英] Alamofire 4.0 Upload MultipartFormData Header
本文介绍了Alamofire 4.0上传MultipartFormData标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何在Alamofire 4.0的上传功能中添加身份验证标头?
How do we add an authentication header to the upload function of Alamofire 4.0?
下面是示例代码,但我认为无法在标题中添加标头函数。
below is the sample code, however I see no way in adding a header to the function.
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(unicornImageURL, withName: "unicorn")
multipartFormData.append(rainbowImageURL, withName: "rainbow")
},
to: "https://httpbin.org/post",
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
debugPrint(response)
}
case .failure(let encodingError):
print(encodingError)
}
}
)
以前版本的alamofire支持直接添加标题,但不支持新标题。有什么想法?
Previous version of alamofire supported adding header directly, but not the new one. Any ideas?
推荐答案
我得到了解决方案。
Alamofire.upload(multipartFormData:{ multipartFormData in
multipartFormData.append(unicornImageURL, withName: "unicorn")
multipartFormData.append(rainbowImageURL, withName: "rainbow")},
usingThreshold:UInt64.init(),
to:"https://httpbin.org/post",
method:.post,
headers:["Authorization": "auth_token"],
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
debugPrint(response)
}
case .failure(let encodingError):
print(encodingError)
}
})
希望它能帮到你。
这篇关于Alamofire 4.0上传MultipartFormData标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文