After a lot of research, i find out how to do it...
1.- Use
App::uses('HttpSocket', 'Network/Http'); // you should put this on your controller
2.- this on your function
$HttpSocket = new HttpSocket();
3.- Here comes the data you want to send via POST (in this example i will use the variables i've used.. you can replace them, add more or delete some.. it depends on the info you want to send)
$data = array(
"api_key" => "API KEY",
"user_id" => $idUser,
"event" => "other",
"extra" => array(
"course" => $course,
"price"=> $price )
);
3.- You set the Headers
$request = array(
'header' => array('Content-Type' => 'application/json',
),
);
4.-json_encode it
$data = json_encode($data);
5.- Where are you sending the Post To?, which data?, type of request?, do it this way
$response = $HttpSocket->post('http://api.yourweburl.com/api/', $data, $request);
*.- You can see the response uncommenting this snippet
//pr($response->body());
*.- Finally if you want to redirect somewhere after everything is done.. do it this way...
$this->redirect(array('action' => 'index'));
You should have something like this.
public function actiontooutbound($idUser, $course, $price){
$HttpSocket = new HttpSocket();
$data = array(
"api_key" => "API KEY",
"user_id" => $idUser,
"event" => "other",
"extra" => array(
"course" => $course,
"price"=> $price )
);
$request = array(
'header' => array(
'Content-Type' => 'application/json',
),
);
$data = json_encode($data);
$response = $HttpSocket->post('http://api.outbound.io/api/v1/track', $data, $request);
// pr($data);
//pr($response->body());
$this->redirect(array('action' => 'index'));
}
This is how you call this function from another function (just in case)
$this->actiontooutbound($idUser, $course, $price);
if you have any questions let me now i'll be happy to help you ;)