我已将我的项目迁移到 Swift 3(并使用 Podfile 中的 pod 'Alamofire', '~> 4.0'
将 Alamofire 更新到最新的 Swift 3 版本)。
现在,我在每个 Alamofire.request 上都会收到“调用中的额外参数”错误。例如:
let patientIdUrl = baseUrl + nextPatientIdUrl
Alamofire.request(.POST, patientIdUrl, parameters: nil, headers: nil, encoding: .JSON)
谁能告诉我为什么?
最佳答案
根据Alamofire使用 HTTP 方法进行 4.0.0 版本 URL 请求的文档如下:
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)
因此您的网址请求将是:
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 调用中的额外参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39490839/