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
??
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.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:
… makes a POST request, but you are putting all the data in the query string (where you should be passing it through
encodeURIComponent
first).