ios - 在 Swift 中使用 Alamofire 调用的额外参数“方法”
问题描述
我正在尝试向 Alamofire 发出请求,但错误发生在 parameterer 中method: HTTPMethod
,我使用了提示性参数.post
。
Alamofire.request(OdooAuth.host2!, method: .post, parameters: [String:Any], encoding: JSONEncoding.default, headers: [])
主机没问题,因为如果我尝试其他方式,例如:
AlamofireXMLRPC.request(OdooAuth.host2!, methodName: "execute_kw", parameters: params)
这行得通。
问题是我想使用 JSON 而不是 XML。
XCode 中的错误:
我在网上、Github、Stackoverflow 上搜索了很多帖子,但类似的问题没有答案或没有解决我的问题。
解决方案
标头应该是字典[:]
而不是数组[]
,这就是方法签名不匹配的原因。
尝试
let headers = [
"Content-Type": "application/json",
"Accept": "application/json"
]
Alamofire.request(url, method: .post, parameters: params, encoding: JSONEncoding.default, headers: headers).responseJSON { response in
// handle the response here
}
推荐阅读
- python - 在python中用类变量覆盖开槽属性
- angular - 在 Konva 中逐步调整矩形大小
- python - Doc2Vec build_vocab 方法失败
- c++ - if then C++中的三元运算符
- azure - 如何确定 Azure 虚拟机是否(未)托管?
- python - 功能。ValueError:使用可迭代设置时必须具有相等的 len 键和值。熊猫
- java - 未找到 ID 为 com.android.application 的插件
- python - 如何获取 tkinter 标签的用户输入?
- html - 单选按钮可以多选和标签不能显示在 1 行问题
- c# - c++和c#大值sin函数结果不同