add clear
This commit is contained in:
+46
-27
@@ -653,44 +653,63 @@ class HttpClient
|
|||||||
*/
|
*/
|
||||||
private function curlParse($url, $data)
|
private function curlParse($url, $data)
|
||||||
{
|
{
|
||||||
$ch = curl_init();
|
$curl = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, $this->createRequestUrl($url, $data));
|
curl_setopt($curl, CURLOPT_URL, $this->createRequestUrl($url, $data));
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT, 120);// 超时设置
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper($this->method));
|
||||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
curl_setopt($curl, CURLOPT_TIMEOUT, 120);// 超时设置
|
||||||
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
|
curl_setopt($curl, CURLOPT_HEADER, true);
|
||||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); // 超时设置
|
curl_setopt($curl, CURLOPT_NOBODY, FALSE);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//返回内容
|
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30); // 超时设置
|
||||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);// 跟踪重定向
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); //返回内容
|
||||||
// curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); // 跟踪重定向
|
||||||
if ($headers = $this->parseHeaderMat()) {
|
// curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
$this->parseHeader($curl);
|
||||||
}
|
$this->parseSslFile($curl);
|
||||||
if (!empty($this->agent)) {
|
if (!empty($this->agent)) {
|
||||||
curl_setopt($ch, CURLOPT_USERAGENT, $this->agent);
|
curl_setopt($curl, 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);
|
|
||||||
}
|
}
|
||||||
if ($this->method == self::POST) {
|
if ($this->method == self::POST) {
|
||||||
curl_setopt($ch, CURLOPT_POST, 1);
|
curl_setopt($curl, CURLOPT_POST, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->method != self::GET) {
|
if ($this->method != self::GET) {
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||||
}
|
}
|
||||||
|
$output = curl_exec($curl);
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($this->method));
|
|
||||||
$output = curl_exec($ch);
|
|
||||||
if ($output === false) {
|
if ($output === false) {
|
||||||
throw new Exception(curl_error($ch));
|
throw new Exception(curl_error($curl));
|
||||||
}
|
}
|
||||||
curl_close($ch);
|
curl_close($curl);
|
||||||
return $output;
|
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
|
* @param $output
|
||||||
* @return array
|
* @return array
|
||||||
|
|||||||
Reference in New Issue
Block a user