add clear

This commit is contained in:
2020-08-24 11:59:31 +08:00
parent bba7544942
commit 6c94ecc353
+46 -27
View File
@@ -653,44 +653,63 @@ class HttpClient
*/
private function curlParse($url, $data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->createRequestUrl($url, $data));
curl_setopt($ch, CURLOPT_TIMEOUT, 120);// 超时设置
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); // 超时设置
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//返回内容
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);// 跟踪重定向
// curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
if ($headers = $this->parseHeaderMat()) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->createRequestUrl($url, $data));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper($this->method));
curl_setopt($curl, CURLOPT_TIMEOUT, 120);// 超时设置
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_NOBODY, FALSE);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30); // 超时设置
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); //返回内容
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); // 跟踪重定向
// curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
$this->parseHeader($curl);
$this->parseSslFile($curl);
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($curl, CURLOPT_USERAGENT, $this->agent);
}
if ($this->method == self::POST) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POST, 1);
}
if ($this->method != self::GET) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($this->method));
$output = curl_exec($ch);
$output = curl_exec($curl);
if ($output === false) {
throw new Exception(curl_error($ch));
throw new Exception(curl_error($curl));
}
curl_close($ch);
curl_close($curl);
return $output;
}
/**
* @param $curl
*/
private function parseSslFile($curl)
{
$key = $this->getSslKeyFile();
$cert = $this->getSslCertFile();
if (!empty($cert) && file_exists($cert)) {
curl_setopt($curl, CURLOPT_SSLCERT, $cert);
}
if (!empty($key) && file_exists($key)) {
curl_setopt($curl, CURLOPT_SSLKEY, $key);
}
}
/**
* @param $curl
*/
private function parseHeader($curl)
{
$headers = $this->parseHeaderMat();
if (empty($headers)) {
return;
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
}
/**
* @param $output
* @return array