我正在调用POST请求,我从另一个方法提供params,url并得到错误:
Contextual type anyobject cannot be used with dictionary literal
这是我在此处调用并获取错误的方法:
API.sharedInstance.post(NSURL(string: baseURL)!, params: ["name": val, "owner": "John"])
这是我的Alamofire
代码:
func post(url: NSURL, params: AnyObject) {
Alamofire.request(.POST, baseURL, parameters: params as! [String : AnyObject])
.validate()
.responseJSON { response in
switch response.result {
case .Success:
print("Validation Successful")
print("response = \(response)")
case .Failure(let error):
print(error)
}
}
}
答案 0 :(得分:0)
尝试替换
func post(url: NSURL, params: AnyObject) {
Alamofire.request(.POST, baseURL, parameters: params as! [String : AnyObject])
带
func post(url: NSURL, params: [String : AnyObject]) {
Alamofire.request(.POST, baseURL, parameters: params)