php - Alamofire request parameters empty -


i'm trying send post request alarmofire library, request doesn't send parameters properly.

my code:

let parameters : parameters = [     "email": tfloginemail.text! string,     "password": tfloginpassword.text! string ] alamofire.request(url, method: .post, parameters: parameters, encoding: jsonencoding.default).responsejson{ response in     //some code uses response } 

the parameters variable has count of 2 , both values present, response request error email and/or password being empty.

edit: php:

/**  * account login  * url - /login  * method - post  * params - email, password  */ $app->post('/login', function() use ($app) {             // check required params             verifyrequiredparams(array('email', 'password'));              // reading post params             $email = $app->request()->post('email');             $password = $app->request()->post('password');             $response = array();              $db = new dbhandler();             // check correct email , password             if ($db->checklogin($email, $password)) {                 // user email                 $account = $db->getaccountbyemail($email);                  if ($account != null) {                     $response["error"] = false;                     $response['id'] = $account['id'];                     $response['name'] = $account['name'];                     $response['email'] = $account['email'];                 } else {                     // unknown error occurred                     $response['error'] = true;                     $response['message'] = "an error occurred. please try again";                 }             } else {                 // user credentials wrong                 $response['error'] = true;                 $response['message'] = 'login failed. incorrect credentials';             }             echorespnse(200, $response);         });  

i'd know i'm doing wrong. in advance.

apparently server expects request body url-encoded string, not json. use encoding: urlencoding.httpbody instead of encoding: jsonencoding.default fix issue.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -