I am trying to send a POST request using the Alarmofire library, but the request does not send the parameters properly.
My code is:
let parameters : Parameters = [
"email": tfLoginEmail.text! as String,
"password": tfLoginPassword.text! as String
]
Alamofire.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON{ response in
}
The parameter variable has a counter of 2 and both values are present, but the answer to this request is an error that the mail and / or password are empty.
EDIT:
My PHP:
$app->post('/login', function() use ($app) {
verifyRequiredParams(array('email', 'password'));
$email = $app->request()->post('email');
$password = $app->request()->post('password');
$response = array();
$db = new DbHandler();
if ($db->checkLogin($email, $password)) {
$account = $db->getAccountByEmail($email);
if ($account != NULL) {
$response["error"] = false;
$response['id'] = $account['id'];
$response['name'] = $account['name'];
$response['email'] = $account['email'];
} else {
$response['error'] = true;
$response['message'] = "An error occurred. Please try again";
}
} else {
$response['error'] = true;
$response['message'] = 'Login failed. Incorrect credentials';
}
echoRespnse(200, $response);
});
I would like to know what I am doing wrong. Thanks in advance.
source
share