我正在尝试在 Swift 中使用 Alamofire 发出带有标头的发布请求。然而,我不断得到方法调用中的额外参数错误。我正在使用 Alamofire 4.5 版本。我无法找出错误。
请查找附件中的代码
let headers = ["Authorization": token, "Content-Type": "application/json"]
Alamofire.request("http://localhost:8000/create", method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers).responseJSON { response in
}
按照这种方式添加标题
let headers = ["Authorization" : "Bearer "+accessToken!+"",
"Content-Type": "application/json"]
Alamofire.request(URL, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers).responseJSON
{ (response:DataResponse) in
switch(response.result)
{
case .success(let value):
//for Json serialization add in success:
let JSON = try JSONSerialization.jsonObject(with: response.data! as Data, options:JSONSerialization.ReadingOptions(rawValue: 0))
guard let JSONDictionary: NSDictionary = JSON as? NSDictionary else {
return
}
completionHandler(JSONDictionary as? NSDictionary, nil)
case .failure(let error):
completionHandler(nil, error as NSError?)
break
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)