/** * 下载远程 HTTP 请求内容。 * * @param string $url * @param HTTPOption $option * @param array $info * @return string * @throws ArgumentException */ private function _download($url, $option, &$info) { if (!$option) { throw new ArgumentException('必须指定 HTTPOption 参数对象。', -1); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $option->getConnectTimeout()); curl_setopt($ch, CURLOPT_TIMEOUT, $option->getTimeout()); curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, $option->getDnsCacheTimeout()); curl_setopt($ch, CURLOPT_USERAGENT, $option->getUserAgent()); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $pfs = $option->getPostFields(); if (false !== $pfs) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $pfs); } if ($option->getOnProgress() != NULL) { curl_setopt($ch, CURLOPT_NOPROGRESS, false); curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, $option->getOnProgress()); } if ($option->getCookies()) { curl_setopt($ch, CURLOPT_COOKIE, $option->getCookies()); } if ($option->getProxyHost()) { curl_setopt($ch, CURLOPT_PROXY, $option->getProxyHost()); } $content = curl_exec($ch); if (!curl_errno($ch)) { $info = curl_getinfo($ch); } curl_close($ch); return $content; }