Use Curl With Magento and Zend Framework
Tuesday, 25. October 2011
Just a little snippet of curl implementation inside Magento for anyone interested.
try { $http = new Varien_Http_Adapter_Curl(); $config = array('timeout' => 30); # Or whatever you like! ## You attach proxy with your custom implementation like this:: if ($this->getUseProxy()) { $config['proxy'] = $this->getProxyHost(). ':' . $this->getProxyPort(); } ## You can add ssl certificate with your custom implementation like this:: if ($this->getUseCertAuthentication()) { $config['ssl_cert'] = $this->getApiCertificate(); } $http->setConfig($config); ## make a POST call $http->write(Zend_Http_Client::POST, $this->getApiUrl(), '1.1', array(), $requestQuery); ## Get Response $response = $http->read(); } catch (Exception $e) { $debugData['http_error'] = array('error' => $e->getMessage(), 'code' => $e->getCode()); $this->_debug($debugData); throw $e; } # Close Call $http->close();