From d2977fd9ab57e7596f812301b253c89e7fe61533 Mon Sep 17 00:00:00 2001 From: topnuomi <1130395124@qq.com> Date: Fri, 11 Oct 2019 20:10:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0CLI=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E3=80=81=E5=88=9B=E5=BB=BAHTTP=E8=AF=B7=E6=B1=82=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E8=BF=94=E5=9B=9E=E8=AF=B7=E6=B1=82=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/library/App.php | 2 +- framework/library/functions/functions.php | 10 +++++++--- framework/library/http/Request.php | 9 +++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/framework/library/App.php b/framework/library/App.php index 3ba072c..053f617 100644 --- a/framework/library/App.php +++ b/framework/library/App.php @@ -65,7 +65,7 @@ class App private static function initRoute() { $driver = null; - if (php_sapi_name() == 'cli') { + if (Request::instance()->isCLI()) { // 命令行运行程序 $driver = new Command(); } else { diff --git a/framework/library/functions/functions.php b/framework/library/functions/functions.php index 810c0d3..29e1f81 100644 --- a/framework/library/functions/functions.php +++ b/framework/library/functions/functions.php @@ -160,10 +160,14 @@ function create_http_request($url, $data = [], $header = []) curl_setopt($curl, CURLOPT_HEADER, $header); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); - $res = curl_exec($curl); + $response = curl_exec($curl); + if (!empty($header)) { + $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); + $response = substr($response, $headerSize); + } curl_close($curl); - if ($res) { - return $res; + if ($response) { + return $response; } return false; } diff --git a/framework/library/http/Request.php b/framework/library/http/Request.php index 0c97f08..25c4e62 100644 --- a/framework/library/http/Request.php +++ b/framework/library/http/Request.php @@ -124,6 +124,15 @@ class Request return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); } + /** + * CLI + * @return boolean + */ + public function isCLI() + { + return (php_sapi_name() == 'cli'); + } + /** * 创建一个请求(post或get取决于data是否有值且不为空或空数组) * @param string $url