使用带有自定义标头的alamofire发布http请求时出错

时间:2018-08-29 06:57:43

标签: ios swift httprequest alamofire

我收到此错误:

  

responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.inputDataNilOrZeroLength)

当我想使用alamofire发布http请求时

这是我的代码:

let dict = UserDefaults.standard.object(forKey: "dict") as! [String : Any]
let token = "Bearer " + (dict["token"] as! String)
let header = ["Authorization" : token]
let parameters: Parameters = ["lat": 36.32914573119686 , "lng": 59.47487354278565 ]

Alamofire.request("http://amoozandeh.ir/api/v1/cedrus/app-index", method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: header).validate().responseJSON { response in
    print(response)}

令牌和api正确

非常感谢

0 个答案:

没有答案