/** * 运行 CLI 应用程序。 */ function start() { $option = new HTTPOption(); // $option->setEncodeCookies(true); // $option->setCookies($this->cookies); $option->setAcceptMimeType('text/html'); $http = HTTP::instance($this->ctx); $a = $http->downloadString('http://www.9abbs.com/forum.php?mod=viewthread&tid=471406&extra=page%3D1%26filter%3Dtypeid%26typeid%3D31%26typeid%3D31', $option); // try { // $obj = new PHPMailer(); // // $obj->SMTPDebug = 0; // $obj->isSMTP(); // $obj->setFrom('*****@*****.**', '小石头'); // $obj->addAddress('*****@*****.**', '李磊'); // $obj->SMTPAuth = true; // $obj->Host = 'smtp.126.com'; // $obj->Port = 25; // $obj->Username = '******'; // $obj->Password = '******'; // $obj->Subject = 'SMTP 测试邮件!'; // $obj->Body = '来自 PHPMailer 的测试邮件!'; // $obj->CharSet = 'UTF-8'; // // if ($obj->send()) // Console::info('发送成功!'); // else // Console::error('发送失败!'); // } catch (Exception $ex) { // Console::error($ex->getMessage() . PHP_EOL . $ex->getTraceAsString()); // } }
/** * 下载远程 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); } $content = \http_get($url, $option->getOptions(), $info); return $content; }
/** * 下载远程 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; }