0

I've created a login api and here it is.

enter image description here enter image description here

Here's how i set my session on android enter image description here

Now this API is currently working on android by using Retrofit and I am currently making it to work also on IOS using Alamofire and by using the API I made from android but it's very confusing because it always return success even though I input the incorrect credential. Here's the code on xcode . I just made a simple one first

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
}

Hope someone can help me out. Thanks

1 Answers1

2

The way you backend is written, it is always returning OK response to the request. You should set some header with status code and content, like 200 in case of success and 500 in case of any error.

Here how you can do this in php. PHP: How to send HTTP response code?

Ahsan Sohail
  • 660
  • 6
  • 17
  • 1
    yes the response will always be in success. I do not have much idea about xcode but in javascript when you do .then() or .catch() for an api request .catch() will only catch error if the header of response is not a success status code (success code:200, error codes: 400 or 500) – Ahsan Sohail Oct 29 '18 at 17:51
  • Do you have any recommendation site for xcode and creating web api for ios? –  Oct 29 '18 at 17:58
  • web api should be independent with xcode or any other platform. You can use nodejs, php, c# pretty much everything with xcode. The mention behavior would be same throughout unless you change the backend code and send proper response content rather just echo json. – Ahsan Sohail Oct 29 '18 at 18:15
  • No it did not but i helps me . I created a new API for IOS. –  Oct 30 '18 at 06:49