When I'm doing POST query by node.js filled with some data to Kohana, I always obtain in $this->request->post() empty array, but when I'm doing it by browser native JavaScript ajax call - it obtains proper data - which I've sent.
Node.js code (I'm using request library) - not working:
request.post(
'http://someurl',
{ id : 'ididididid' },
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log('returned BODY:', body);
}
}
);
Node.js is obtaining response (statusCode == 200) but it's empty array
jQuery code - working well:
$.ajax({
type: 'POST',
url : 'http://someurl',
dataType : 'JSON',
data : {
id : 'idididid'
},
done : function(data) {
console.log(data.responseText);
}
});
Kohana code (inside controller):
$data = $this->request->post();
echo json_encode($data);
What am I doing wrong here?
In Kohana, you don't use $this->request->post for the global $_POST var, that's intended for internal (sub) requests.
In your case, you'd do simply:
$this->response->body(json_encode($_POST));
Make sure you always assign the response to the body, since that's the correct way of doing it in Kohana
If you would to do:
Request::factory('/someurl')->post(array('id' => 'idididid'))->execute();
Then your $this->request->post would return the data