I have a function in Zend Framework 2 which sends CURL requests to an API and return results like below :
use Zend\Http\Client as HttpClient;
public function curl($url, array $params, $method = "POST"){
$client = new HttpClient();
$client->setAdapter('Zend\Http\Client\Adapter\Curl');
$client->setUri($url);
$client->setOptions(array(
'maxredirects' => 0,
'timeout' => 30
));
$client->setMethod($method);
$client->setHeaders(array(
'username: xxxxxxx',
'password: xxxxxxx',
));
//if(!empty($params)) {
if ($method == "POST" || $method == "PUT") {
$client->setParameterPOST($params);
} else {
$client->setParameterGET($params);
}
//}
$response = $client->send();
return $response;
}
and calling it as :
$response = $this->api->curl($api_url, array('paramName' => "value"), "DELETE");
But it is unable to send parameter along with the request and API returning 500 internal server error with Exception.