Mawg Mawg - 2 months ago 22
PHP Question

POST data from Chrome PostMan plug-in is empty in Eclipse PDT

I am trying to debug HTTP POST data sent to some AJAX PHP in Eclipse PDT and it is new to me, so I am probably making some very basic mistake.

I found what seems to be an excellent Chrome browser plugin: PostMan

I have defined my request thus:

enter image description here

Which is trying to emulate my AngulrJs code (which works)

var postData = { userName: $scope.registrationData.userName,
email: $scope.registrationData.email,
password: forge_sha256($scope.registrationData.password)
};

var url = HOST + 'api/register.php';

$http.post(url, postData)


If I just use the AngularJs from a browser page, it works and the PHP returns what I expect it to.

BUT, when I use Postman, then in my PHP code

$postData = file_get_contents("php://input");
$request = json_decode($postData, true);


I find that
$_POST
is empty.

What am I doing wrongly (or is there a simpler way to debug HTTP Post with Eclipse PDT)?




[Update] Thanks, @Rubelet, for pointing out that the POST data should go in the body, not the headers.

If I encode it as form data

enter image description here

the received POST data is still empty. I am guessing that I should use "raw", but how do I encode? As JSON?

Answer

You are embedding your data in the Header section of PostMan. These are for HTTP Headers and not what you want. When using angular's post method, the parameters are in fact embedded into the Body section of a POST request.

Put your parameters in the Body section of Postman and it should work.

Comments