We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

What is the right way to access POST data sent using curl ?

From a web app i use curl to send a POST request to my api, $params is an array with 3 variables,uname, email and type

$POSTFIELDS = http_build_query($params); curl_setopt($ch, CURLOPT_POSTFIELDS, $POSTFIELDS);

//On the api side - $uname is always empty, email and type

$uname = $this->di['request']->getPost("uname"); $email = $this->di['request']->getPost("email"); $type = $this->di['request']->getPost("type");

However $this->di['request']->getRawBody() gives me

uname=aa&email=el%40emanonlabs.com&type=aa

how do you access individual post variables? or do i have to explode($params, '=') selectively on getRawBody() IF it is a curl request ? is there a cleaner way?



51.1k

just add

curl_setopt($ch, CURLOPT_POST, 1);

No this makes no difference, i already had

curl_setopt($ch, CURLOPT_POST, TRUE);

edited Dec '15

Correct way to do a POST request with libcurl is:

curl_setopt_array($this->curlHandle, [CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $this->encodedPayload]);

So, you're missing CURLOPT_POST on your http client.