[Swift, Alamofire]: responseValidationFailed 错误代码 400
[Swift, Alamofire]: responseValidationFailed with error code 400
我的问题基本上就在标题上。我正在尝试 运行 的代码就在下面。 VVV
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,但我认为这与问题没有必然关系。
非常感谢任何帮助。
错误日志 responseValidationFailed(Alamofire.AFError.ResponseValidationFailureReason.unacceptableStatusCode(400)) 清楚地表明您遇到了 400 错误。在 W3.org 中解释为
400 Bad Request:
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
所以你需要检查你的请求URL是否正确。
此外,您正在使用请求的 validate() 方法,该方法应该获得响应状态代码 200...299,但您得到的响应代码是 400。这就是为什么它在错误日志中被称为 acceptableStatusCode(400) 的原因。
也见 this。
我的问题基本上就在标题上。我正在尝试 运行 的代码就在下面。 VVV
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,但我认为这与问题没有必然关系。
非常感谢任何帮助。
错误日志 responseValidationFailed(Alamofire.AFError.ResponseValidationFailureReason.unacceptableStatusCode(400)) 清楚地表明您遇到了 400 错误。在 W3.org 中解释为
400 Bad Request: The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
所以你需要检查你的请求URL是否正确。
此外,您正在使用请求的 validate() 方法,该方法应该获得响应状态代码 200...299,但您得到的响应代码是 400。这就是为什么它在错误日志中被称为 acceptableStatusCode(400) 的原因。
也见 this。