Alamofire Swift 3.0 调用中的额外参数

标签 alamofire swift3

我已将我的项目迁移到 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/

相关文章:

ios - 如何在 iOS 设备中解锁屏幕后立即激活并打开我的应用程序

ios - 从自定义键盘应用程序扩展发出 HTTP 请求

swift - 是否可以优化代码片段?

iphone - AlamofireNetworkActivityIndi​​cator 不工作

swift - Swift 3 中的 Alamofire 与 iOS 8

ios - 像 Instagram api 一样设置

ios - 如何更改 MFMessageComposeViewController 的导航栏颜色?

ios - Tableview Like Snapchat 发送功能(多选和可滑动标签)

ios - 使用 Alamofire 和 AlamofireImage 延迟加载图像在第一次加载时不工作

node.js - nodejs api和swift app之间的连接