gpt4 book ai didi

ios - Alamofire参数编码,字典中的字典

转载 作者:行者123 更新时间:2023-11-30 13:04:18 25 4
gpt4 key购买 nike

想要使用 Swift 将其发送到 Alamofire...

curl -X POST https://content.dropboxapi.com/2/files/download    
--header "Authorization: Bearer ab-xxx-x-x"
--header "Dropbox-API-Arg: {\"path\": "/acme101/acmeX100/acmeX100.001.png\"}"

但是不知道如何将您在此处看到的第二个 --header 获取到代码中?尝试了几次不同的组合,但是......

JSON: 114 bytes Optional("Error in call to API function \"files/download\": Must provide HTTP header \"Dropbox-API-Arg\" or URL parameter \"arg\".")

我提供了它,但显然不正确?

let subPart: NSDictionary = ["path": sourcePath]
let headers:HTTPHeaders = ["Authorization": "Bearer " + token2Save, "Dropbox-API-Arg": String(describing: subPart)]

Alamofire.request("https://content.dropboxapi.com/2/files/download", method: .post, encoding: JSONEncoding.init(options: []), headers: headers).responseData(completionHandler: {feedback in

最佳答案

Eureka !!谢谢 UB 先生给我这些建议。找到了解决方案。

let subPart: Dictionary =  ["path":sourcePath]
do {
let data = try JSONSerialization.data(withJSONObject: subPart, options: [])
let dataString = String(data: data, encoding: .utf8)
headers = ["Authorization": "Bearer " + token2Save, "Dropbox-API-Arg": dataString!]
} catch {
print("crunch")
}

Alamofire.request("https://content.dropboxapi.com/2/files/download", method: .post, encoding: JSONEncoding.init(options: []), headers: headers).responseData(completionHandler: {feedback in
guard feedback.result.value != nil else {
print("Error: did not receive data", print("request \(request) feedback \(feedback)"))
return
}
guard feedback.result.error == nil else {
print("error calling POST on list_folder")
print(feedback.result.error)
return
}
if let JSON = feedback.result.value {
print("JSON: \(JSON)")
let dataString = String(data: JSON, encoding: .utf8)
print("JSON: \(JSON) \(dataString)")
}
if let IMAGE = feedback.result.value {
sharedDataAccess.fnData(index2seek: 0, fnData: feedback.result.value! as Data)
NotificationCenter.default.post(name: Notification.Name("previewPane"), object: nil, userInfo: nil)
}
})

关于ios - Alamofire参数编码,字典中的字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39569211/

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