简体   繁体   English

Alamofire-responseSerializationFailed

[英]Alamofire - responseSerializationFailed

I really need help with this one. 我真的需要帮助。 I'm trying to do POST request using Alamofire, but for some reason I'm always getting an error from the title. 我正在尝试使用Alamofire进行POST请求,但是由于某些原因,我总是从标题中得到一个错误。 When I test in POSTMAN, I'm getting okay response. 当我在POSTMAN中进行测试时,得到的响应很好。 Here is screenshot from POSTMAN, just to get things clearer: 这是POSTMAN的屏幕截图,目的是为了使事情更清晰:

在此处输入图片说明

And this is how I'm calling this API in code: 这就是我在代码中调用此API的方式:

let parameters: Parameters = [
        "data": [
            "action":"homeimages"
        ]
    ]

    print("Params: \(parameters)")

    Alamofire.request(Constants.API_URL_2, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON {
        response in
        print("Response: \(response)")
        switch response.result {
        case .success(let value):
            print("Response: \(value)")
            break
        case .failure(let error):
            print(error)
        }
    }

As far as I know responseserializationfailed error, mostly error with API itself however as you stated, you are getting response in POSTMAN please check below things : 据我所知responseerializationailed失败的错误,主要是API本身的错误,但是正如您所说,您正在POSTMAN中获得响应,请检查以下内容:

  1. URL(check small/caps well), parameters are correct(check caps and dictionary format as well) URL(检查小写/大写),参数正确(检查大写和字典格式)
  2. Sometimes we don't need below (optional) parameter , delete this parameter and check 有时我们不需要下面的(可选)参数,删除此参数并检查

     encoding: JSONEncoding.default 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM