/** * Send a HTTP Post request * * @param string $url * @param array $postData * @param array $params = array() * @return Varien_Object */ protected function _post($postUrl, array $postData, array $params = array()) { $postString = ''; $params = new Varien_Object($params); foreach($postData as $field => $value) { $postString .= urlencode($field) .'='.urlencode($value).'&'; } $postString = rtrim($postString, '&=?'); $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $postUrl); curl_setopt($ch,CURLOPT_POST, count($postData)); curl_setopt($ch,CURLOPT_POSTFIELDS, $postString); if ($params->getHeader()) { curl_setopt($ch, CURLOPT_HEADER, 1); } if ($params->getFollowLocation()) { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); } if ($params->getReturnTransfer()) { curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); } $result = curl_exec($ch); if (curl_errno($ch)) { throw new Exception('Curl error: ' . curl_error($ch)); } $ch = curl_close($ch); return new Varien_Object(array('channel' => $ch, 'result' => $result)); }
/** * Send a HTTP Post request * * @param string $url * @param array $postData * @param array $params = array() * @return Varien_Object */ protected function _post($postUrl, array $postData, array $params = array()) { $postString = ''; $params = new Varien_Object($params); foreach ($postData as $field => $value) { $postString .= urlencode($field) . '=' . urlencode($value) . '&'; } $postString = rtrim($postString, '&=?'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $postUrl); curl_setopt($ch, CURLOPT_POST, count($postData)); curl_setopt($ch, CURLOPT_POSTFIELDS, $postString); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_TIMEOUT, 5); if (strpos($postUrl, 'https://') !== false) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); } if ($params->getHeader()) { curl_setopt($ch, CURLOPT_HEADER, 1); } if ($params->getFollowLocation()) { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); } if ($params->getReturnTransfer()) { curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); } $result = curl_exec($ch); if (curl_errno($ch)) { throw new Exception('Curl error: ' . curl_error($ch)); } $ch = curl_close($ch); return new Varien_Object(array('channel' => $ch, 'result' => $result)); }