Using Zend/Http and cURL I want to create a function that depending whether I pass $data to function or not it uses get or post way. I used this:
function Post_Curl_Data ($url, $data = ‘’, $header = ‘’) {
$options = array(CURLOPT_RETURNTRANSFER => 1);
if (!empty($data)) {
$options += array(CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $data);
}
if (!empty($header)) {
$options += array(CURLOPT_HTTPHEADER => $header);
}
$config = array(
'adapter' => 'Zend\\Http\\Client\\Adapter\\Curl',
'curloptions' => $options
);
$client = new Zend\\Http\\Client($url, $config);
$response = $client->send();
return trim($response->getContent());
}
It works fine with get method, but actually does not post $data to url however I did set: CURLOPT_POST => 1 and CURLOPT_POSTFIELDS => $data
Plz advice what wrong I did?