Alamofire自定义参数 [英] Alamofire custom parameters
本文介绍了Alamofire自定义参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将此卷曲调用转换为Swift中的Alamofire。
I am trying to convert this curl call to Alamofire in Swift.
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\"}"
我认为这个.. 。
let headers:HTTPHeaders = ["Authorization": "Bearer " + token2Save]
let moreheaders:Parameters = ["Dropbox-API-Arg": ["path":sourcePath]]
Alamofire.request("https://content.dropboxapi.com/2/files/download", parameters: moreheaders, encoding: URLEncoding(destination: .queryString), headers: headers).responseJSON { feedback in
guard feedback.result.value != nil else {
print("Error: did not receive data", print("request \(request) feedback \(feedback)"))
return
}
但是很好它不起作用,它崩溃...
But of course it doesn't work, it crashes with ...
request (Function) feedback FAILURE: responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}))
Error: did not receive data ()
这需要在标题中,而不是正文。
This needs to be in the header, not the body.
推荐答案
let headers:HTTPHeaders = ["Authorization": "Bearer " + token2Save]
let moreheaders:Parameters = ["Dropbox-API-Arg": ["path":sourcePath]]
Alamofire.request("https://content.dropboxapi.com/2/files/download", parameters: moreheaders, encoding: URLEncoding(destination: .queryString), headers: headers).responseJSON { feedback in
guard feedback.result.value != nil else {
print("Error: did not receive data", print("request \(request) feedback \(feedback)"))
return
URLEncoding(destination:.queryString),headers:headers).responseJSON
用responseString替换responseJSON并检查你对webservice的响应..它将导致获得错误行。
Replace responseJSON with responseString and check your response from webservice.. it will lead to get the error line.
这篇关于Alamofire自定义参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文