增加CLI判断、创建HTTP请求不再返回请求头
This commit is contained in:
parent
5f9f9e2c12
commit
d2977fd9ab
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue