From 016885ba166ea4d3b584ba8d2f19f9b900526aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ms=C2=B7xl?= Date: Sat, 14 Nov 2020 03:11:17 +0800 Subject: [PATCH] 3 --- wchat/common/HttpClient.php | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/wchat/common/HttpClient.php b/wchat/common/HttpClient.php index 6f3131d..2fca7b9 100644 --- a/wchat/common/HttpClient.php +++ b/wchat/common/HttpClient.php @@ -648,30 +648,18 @@ class HttpClient private function curlParse($url, $data) { $ch = curl_init(); - - var_dump($this->createRequestUrl($url, $data)); - curl_setopt($ch, CURLOPT_URL, $this->createRequestUrl($url, $data)); if ($this->timeout > 0) { curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); // 超时设置 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout); // 超时设置 } curl_setopt($ch, CURLOPT_HEADER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, $this->parseHeaderMat()); - var_dump($this->parseHeaderMat()); - - if ($headers = $this->parseHeaderMat()) { - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - } + $this->setSslFile($ch); if (!empty($this->agent)) { curl_setopt($ch, CURLOPT_USERAGENT, $this->agent); } - if (file_exists($cert = $this->getSslCertFile())) { - curl_setopt($ch, CURLOPT_SSLCERT, $cert); - } - if (file_exists($key = $this->getSslKeyFile())) { - curl_setopt($ch, CURLOPT_SSLKEY, $key); - } curl_setopt($ch, CURLOPT_NOBODY, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//返回内容 @@ -681,7 +669,6 @@ class HttpClient if ($this->method == self::POST) { curl_setopt($ch, CURLOPT_POST, 1); } - if ($this->method != self::GET) { curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } @@ -696,6 +683,20 @@ class HttpClient } + /** + * @param resource $ch + */ + private function setSslFile($ch) + { + if (file_exists($cert = $this->getSslCertFile())) { + curl_setopt($ch, CURLOPT_SSLCERT, $cert); + } + if (file_exists($key = $this->getSslKeyFile())) { + curl_setopt($ch, CURLOPT_SSLKEY, $key); + } + } + + /** * @param $url * @param $params @@ -986,7 +987,7 @@ class HttpClient } $headers = []; foreach ($this->header as $key => $val) { - $header = $key . ':' . $val; + $header = $key . ': ' . $val; if (in_array($header, $headers)) { continue; }