add clear
This commit is contained in:
@@ -615,6 +615,35 @@ class HttpClient
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param $params
|
||||
* @return array|mixed|Result
|
||||
* 上传文件
|
||||
*/
|
||||
public function upload($url, $params)
|
||||
{
|
||||
try {
|
||||
$output = $this->curlParse($url, $params);
|
||||
if ($output === FALSE) {
|
||||
return new Result(['code' => 500, 'message' => $output]);
|
||||
}
|
||||
[$header, $body, $status] = $this->explode($output);
|
||||
if ($status != 200 && $status != 201) {
|
||||
$data = new Result(['code' => $status, 'message' => $body, 'header' => $header]);
|
||||
} else {
|
||||
$data = $this->structure($body, $params, $header);
|
||||
}
|
||||
return $data;
|
||||
} catch (\Throwable $exception) {
|
||||
$response['code'] = 500;
|
||||
$response['message'] = $exception->getMessage();
|
||||
$response['data'] = array_slice($exception->getTrace(), 0, 6);
|
||||
$response['header'] = [];
|
||||
return new Result($response);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param $data
|
||||
@@ -631,14 +660,15 @@ class HttpClient
|
||||
if ($headers = $this->parseHeaderMat()) {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
}
|
||||
|
||||
if (!empty($this->agent)) {
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, $this->agent);
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_SSLCERT, $this->getSslCertFile());
|
||||
curl_setopt($ch, CURLOPT_SSLCERT, $this->getSslCertFile());
|
||||
curl_setopt($ch, CURLOPT_SSLKEY, $this->getSslKeyFile());
|
||||
if ($this->getSslCertFile()) {
|
||||
curl_setopt($ch, CURLOPT_SSLCERT, $this->getSslCertFile());
|
||||
}
|
||||
if ($this->getSslKeyFile()) {
|
||||
curl_setopt($ch, CURLOPT_SSLKEY, $this->getSslKeyFile());
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); // 超时设置
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//返回内容
|
||||
|
||||
Reference in New Issue
Block a user