【问题标题】:[Swift, Alamofire]: responseValidationFailed with error code 400[Swift,Alamofire]:responseValidationFailed 错误代码 400
【发布时间】:2017-02-21 09:26:17
【问题描述】:

我的问题基本上出在标题上。我试图运行的代码就在下面。呜呜呜

let unfollow = "https://api.instagram.com/v1/users/\(userID)/relationship?access_token=\(access_token)&action=unfollow"

    Alamofire.request(unfollow, method: .post).validate().responseJSON(completionHandler: {
        response in

        switch response.result {

        case .success(let value):

            let data = JSON(value)["data"]
            print(data["outgoing_status"].stringValue)

        case .failure(let error):
            print(error)

        }

    })

我收到的确切控制台错误是:responseValidationFailed(Alamofire.AFError.ResponseValidationFailureReason.unacceptableStatusCode(400))

顺便说一句,我正在使用 Instagram API,但我认为这与问题无关。

非常感谢任何帮助。

【问题讨论】:

  • 您能否检查unfollow 变量的值并将其添加到帖子中。我怀疑你的字符串中有一堆Optional(…)

标签: swift post instagram alamofire


【解决方案1】:

错误日志 responseValidationFailed(Alamofire.AFError.ResponseValidationFailureReason.unacceptableStatusCode(400)) 清楚地表明您收到 400 错误。 W3.org 中解释为

400 错误请求: 由于语法错误,服务器无法理解该请求。客户端不应该在没有修改的情况下重复请求。

所以你需要检查你请求的 URL 是否正确。

此外,您正在使用请求的 validate() 方法,该方法应该获得响应状态代码 200...299,但您得到的响应代码为 400。这就是为什么它在错误日志中被称为 unacceptableStatusCode(400)。

另请参阅this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 2018-03-03
    • 1970-01-01
    相关资源
    最近更新 更多