加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Alamofire Swift 3.0呼叫中的额外参数

发布时间:2020-12-14 05:58:37 所属栏目:百科 来源:网络整理
导读:我已将我的项目迁移到Swift 3(并且在Podfile中将Alamofire更新为最新的Swift 3版本,并使用pod’Alamofire’,’? 4.0′)。 我现在每个Alamofire.request都会得到一个“额外的调用参数”错误。例如: let patientIdUrl = baseUrl + nextPatientIdUrlAlamofir
我已将我的项目迁移到Swift 3(并且在Podfile中将Alamofire更新为最新的Swift 3版本,并使用pod’Alamofire’,’?> 4.0′)。

我现在每个Alamofire.request都会得到一个“额外的调用参数”错误。例如:

let patientIdUrl = baseUrl + nextPatientIdUrl
Alamofire.request(.POST,patientIdUrl,parameters: nil,headers: nil,encoding: .JSON)

有人可以告诉我为什么吗

根据 Alamofire文档4.0.0版本的URL请求与HTTP方法将如下:
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)

所以你的url请求将是:

Alamofire.request(patientIdUrl,method: .post,encoding: JSONEncoding.default,headers: nil)

并且示例请求将是:

Alamofire.request(url,parameters: param,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
}

希望这可以帮助!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读