gpt4 book ai didi

ios - Alamofire 4.0 上传 MultipartFormData header

转载 作者:IT王子 更新时间:2023-10-29 05:11:39 25 4
gpt4 key购买 nike

Alamofire 4.0 的上传功能如何添加认证头?

下面是示例代码,但是我看不到向函数添加 header 的方法。

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支持直接添加header,新版不支持。有什么想法吗?

最佳答案

我得到了解决方案。

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)
}
})

希望对你有所帮助。

关于ios - Alamofire 4.0 上传 MultipartFormData header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39630997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com