Alamofire自定义参数
问题描述:
我正试图在Swift中将此卷曲调用转换为Alamofire。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\"}"
而且我想这...
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
}
但当然这是行不通的,它崩溃...
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()
这需要在头,而不是身体。
答
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
URL编码(目标:.queryString),标题:标题).responseJSON
Replace responseJSON with responseString and check your response from webservice.. it will lead to get the error line.
http://*.com/questions/33518839/nsjsonserialization -error-code-3840-invalid-value-around-character-0 –
预期结果是采用哪种格式? –
http://*.com/questions/32355850/alamofire-invalid-value-around-character-0 –