private static function sendByCurl($url, $mode, $params = '', $timeout = 10){ $ch = curl_init(); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if ($mode == 'post') { curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); }else{ $url .= (strpos($url, '?') === false ? '?' : '&') . http_build_query($params); } curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); $errno = curl_errno($ch); if ($errno) { return array( 'errno' => $errno, 'error' => curl_error($ch), ); } curl_close($ch); return $result; }
|