From 4dd4044c4443d28c553c6fa7e1db38fca179be4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 18 Nov 2020 14:48:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Client/Curl.php | 41 +++++++++----------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/HttpServer/Client/Curl.php b/HttpServer/Client/Curl.php index 84ab850a..b84a0901 100644 --- a/HttpServer/Client/Curl.php +++ b/HttpServer/Client/Curl.php @@ -43,41 +43,21 @@ class Curl extends ClientAbstracts $host = $isHttps ? 'https://' . $host : 'http://' . $host; $resource = $this->do(curl_init($host . $path), $host . $path, $method); - if ($method === self::POST && !empty($params)) { + if ($isHttps !== false) { + $this->curlHandlerSslSet($resource); + } + if (empty($params)) { + return $resource; + } + var_dump($params); + if ($method === self::POST) { curl_setopt($resource, CURLOPT_POSTFIELDS, HttpParse::parse($params)); } else if ($method === self::UPLOAD) { curl_setopt($resource, CURLOPT_POSTFIELDS, $params); } - - if ($isHttps !== false) { - return $this->curlHandlerSslSet($resource); - } return $resource; } -// -// /** -// * @param $path -// * @param $params -// * @return mixed|resource -// * @throws Exception -// */ -// public function upload($path, $params = []) -// { -// [$host, $isHttps, $path] = $this->matchHost($path); -// -// $host = $isHttps ? 'https://' . $host : 'http://' . $host; -// -// $resource = $this->do(curl_init($host . $path), $host . $path, self::POST); -// -// curl_setopt($resource, CURLOPT_POSTFIELDS, $params); -// -// if ($isHttps !== false) { -// return $this->execute($this->curlHandlerSslSet($resource)); -// } -// return $this->execute($resource); -// } - /** * @param $resource @@ -111,6 +91,7 @@ class Curl extends ClientAbstracts */ private function do($resource, $path, $method) { + curl_setopt($resource, CURLOPT_URL, $path); curl_setopt($resource, CURLOPT_TIMEOUT, $this->getTimeout()); // 超时设置 curl_setopt($resource, CURLOPT_CONNECTTIMEOUT, $this->getConnectTimeout()); // 超时设置 @@ -133,9 +114,6 @@ class Curl extends ClientAbstracts if ($method === self::POST || $method == self::UPLOAD) { curl_setopt($resource, CURLOPT_POST, 1); } - - var_dump($path); - curl_setopt($resource, CURLOPT_URL, $path); curl_setopt($resource, CURLOPT_CUSTOMREQUEST, $method); return $resource; @@ -150,7 +128,6 @@ class Curl extends ClientAbstracts private function execute($curl) { $output = curl_exec($curl); - var_dump($output); if ($output === false) { return $this->fail(400, curl_error($curl)); }