Ionic framework http post request


#1

Hello every once

I want to send post request to remote php file from ionic app to save base64 encoded data in the database, but when i pass post data i can see the post parameter is sent but when i print post response from php file its blank

I have added the sample code i tried

cotroller.js

$http.post("someurl", {data: {"data333": 'peter'}});

in php file when i print $_POST or $_REQUEST its blank array but from my console i can see parameters are passed and its json format {data: {“data333”: ‘peter’}}

i have allowed cross domain in both client and server

i also tried the standard ajax way also

$http.defaults.headers.post["Content-Type"] = 'application/x-www-form-urlencoded; charset=UTF-8';
$http({
        method : 'POST',
        url : 'someurl/',
        headers: {
 'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'

},
data : {“key”: “value”}
})

can anyone help me to pass this data


#2

Have you tried using Fiddler (software) to analyze incoming/outgoing server data?


#3

I’m also finding a similar issue when i use the following from the client side

var url = ‘http://localhost:8100’;
var request = $http.post(url, { params : {“FirstName”: $scope.Model.FName, “LastName”:$scope.Model.LName}},
{headers: { ‘Content-Type’: ‘application/x-www-form-urlencoded; charset=UTF-8’}});

On the server side I tried using the following combination of statements to read the value. But none of them returns the value and it returns undefined. Can someone help me to resolve this.

  console.log("The value of the body is", req.body.FirstName);
  console.log('The value of params is ', req.params.FirstName);
  console.log('The value of body params is ', req.body.params);
  console.log('The value of key is ', keys[0]);
  console.log('The value of param from req.body.Param', req.body.param);