简体   繁体   中英

Cordova: Can not get the request parameters values at server side using $_POST

I am developing mobile application for one of my webapp whose all the data resides on server. On post request data will be sent in response in JSON format. I am doing a post request as follows:

$http.defaults.headers.post['Content-Type'] ='application/x-www-form-urlencoded';
$http.post(base_url+"get/memberLogin.php", {'username':userName, 'password':passWord, 'tempKey':'XHJJUQWERgfrbbbbokaw1222344'}...

the data is getting sent in post request as that of i can see in the firebug of firefox browser. But at server side when i do var_dump($_POST) or var_dump($_REQUEST) i am getting the empty array. How is it so??? As i am posting data on server, it should be captured using $_POST but didnt work

Instead if i send data in following format:

$http.post(base_url+"get/memberLogin.php?username="+userName+"&password="+passWord, {}...

I am getting parameter values at server side using $_REQUEST . What is the problem with $_POST ??

But at server side when i do var_dump($_POST) or var_dump($_REQUEST) i am getting the empty array.

While you are setting the content-type to application/x-www-form-urlencoded, Angular is encoding the data as JSON.

PHP fails to parse it (because it isn't application/x-www-form-urlencoded) so it has no data to populate $_POST wiht.

I am getting parameter values at server side using $_REQUEST. What is the problem with $_POST??

PHP has stupid naming conventions.

$_GET does not contain all data from a GET request. It contains data from a query string.

$_POST does not contain all data from a POST request. It contains data from the request body.

This:

$http.post(base_url+"get/memberLogin.php?username="+userName+"&password="+passWord

… makes a POST request, but you are putting all the data in the query string (where you should be passing it through encodeURIComponent first).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM