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 请求方法封装
最新推荐文章于 2025-09-14 10:15:15 发布
本文介绍了一个用于发起 HTTP 请求的 PHP 函数,该函数利用 cURL 库进行 POST 和 GET 操作,并设置了一些通用的请求头,如 Content-Type 和 Accept。函数能够处理请求并返回 JSON 解析后的数据。
1021

被折叠的 条评论
为什么被折叠?



