How to use curl in yii application


I am using curl in my application first time.

I have create one module named WebService. In Web service url i use action "WebServices" of defaultController


"ServiceTypeMaster-create" is my controller and action name which i have to call.

my webservice function

public function actionWebServices($key)




                    $urls=  explode('-', $key);

                    $json = file_get_contents('php://input');




                        $string = $this->jsonParse($json);

                        $ch = curl_init();

                        $url = Yii::app()->baseUrl.'/'.$urls[0].'/'.$urls[1].'/';



                        $postvars = '';

                        foreach($string as $key=>$value) 


                                    $postvars .= $key . "/" . $value . "/";


                       //this static url used for demo

                        curl_setopt($ch, CURLOPT_URL,  'http://localhost:83/Working-copy/mysite/ServiceTypeMaster/Create' );

                        curl_setopt($ch, CURLOPT_USERPWD, $u.':'.$p);

                        curl_setopt($ch, CURLOPT_FORBID_REUSE, false);

                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

                        curl_setopt($ch, CURLOPT_POST, count($string));

                        curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);


                        $json2 = curl_exec($ch);

                        if ($json2 === false)


                            echo "Error Number:" . curl_errno($ch) . "<br>";

                            echo "Error String:" . curl_error($ch);




                        //echo CJSON::encode($json2);




public function jsonParse($json)


            return  CJSON::decode($json,true);


Now in ServiceTypeMaster Controller how to fetch Post data?? and how to give success response?