Alamofire Swift 3.0 调用中的额外参数 [英] Alamofire Swift 3.0 Extra argument in call
本文介绍了Alamofire Swift 3.0 调用中的额外参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已将我的项目迁移到 Swift 3(并使用 Podfile 中的 pod 'Alamofire', '~> 4.0'
将 Alamofire 更新到最新的 Swift 3 版本).
I have migrated my project to Swift 3 (and updated Alamofire to latest Swift 3 version with pod 'Alamofire', '~> 4.0'
in the Podfile).
我现在在每个 Alamofire.request 上都会收到Extra argument in call"错误.例如:
I now get an "Extra argument in call" error on every Alamofire.request. Eg:
let patientIdUrl = baseUrl + nextPatientIdUrl
Alamofire.request(.POST, patientIdUrl, parameters: nil, headers: nil, encoding: .JSON)
谁能告诉我为什么?
推荐答案
根据 Alamofire 文档针对 4.0.0 版 URL 请求使用 HTTP 方法将如下:
According to Alamofire documentation for version 4.0.0 URL request with HTTP method would be followings:
Alamofire.request("https://httpbin.org/get") // method defaults to `.get`
Alamofire.request("https://httpbin.org/post", method: .post)
Alamofire.request("https://httpbin.org/put", method: .put)
Alamofire.request("https://httpbin.org/delete", method: .delete)
所以你的网址请求将是:
So your url request will be:
Alamofire.request(patientIdUrl, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: nil)
样本请求将是:
Alamofire.request(url, method: .post, parameters: param, encoding: JSONEncoding.default, headers: [AUTH_TOKEN_KEY : AUTH_TOKEN])
.responseJSON { response in
print(response.request as Any) // original URL request
print(response.response as Any) // URL response
print(response.result.value as Any) // result of response serialization
}
希望这有帮助!
这篇关于Alamofire Swift 3.0 调用中的额外参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文