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 = httpbuildquery($params); curlsetopt($ch, CURLOPTPOSTFIELDS, $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?



32.7k

just add

curl_setopt($ch, CURLOPT_POST, 1);

No this makes no difference, i already had

curlsetopt($ch, CURLOPTPOST, 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.