private function _curlRequest($url, $type = 'post', $request_data = '') {
$header = array(
"Content-Type:application/x-www-form-urlencoded;charset=UTF-8",
"Connection:Keep-Alive",
'Accept:application/json',
);
$this->ch = curl_init();
/* cURL settings */
curl_setopt($this->ch, CURLOPT_URL, $url);
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 10);
curl_setopt($this->ch, CURLOPT_HEADER, 0);
curl_setopt($this->ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
if ($type == 'post') {
curl_setopt($this->ch, CURLOPT_POST, true);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $request_data);
}
$result = curl_exec($this->ch);
curl_close($this->ch);
return $data = empty($result) ? array() : json_decode($result, true);
}
php curl 请求方法封装
最新推荐文章于 2024-05-23 16:09:21 发布