我已经创建了一个登录 api,就在这里。
现在这个 API
目前通过使用 Retrofit
在 android 上工作,我目前正在使用 Alamofire
让它在 IOS 上工作,并且通过使用我从 android 制作的 API 但它非常困惑,因为即使我输入了不正确的凭据,它也总是返回成功。这是 xcode 上的代码。我先做了一个简单的
let URL_USER_LOGIN = "https://thelinkoftheapi"
let parameters: Parameters=[
"username": usernameTextField.text!,
"password": passwordTextField.text!,
"operation": "login",
"version" : "1.0.0"
]
Alamofire.request(URL_USER_LOGIN, method: .post, parameters:parameters, encoding: URLEncoding()) .responseString { response in
print(response) // it is always SUCCESS on the console
}
希望有人能帮帮我。谢谢
最佳答案
你后端的编写方式,它总是对请求返回 OK 响应。您应该设置一些带有状态代码和内容的 header ,例如 200 代表成功,500 代表任何错误。
在这里你可以如何在 php 中做到这一点。 PHP: How to send HTTP response code?
关于android - Web API 总是返回成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53050370/