TP5.0 模拟POST与GET请求
/**
* 模拟POST与GET请求
* @param string $url [请求地址]
* @param string $type [请求方式 post or get]
* @param bool|string|array $data [传递的参数]
* @param array $header [可选:请求头] eg: ['Content-Type:application/json']
* @param int $timeout [可选:超时时间]
*/
public function request($url, $type, $data = false, $header = [], $timeout = 0)
{
$cl = curl_init();
// 兼容HTTPS
if (stripos($url, 'https://') !== FALSE) {
curl_setopt($cl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($cl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($cl, CURLOPT_SSLVERSION, 1);
}
// 设置返回内容做变量存储
curl_setopt($cl, CURLOPT_RETURNTRANSFER, 1);
// 设置需要返回Header
curl_setopt($cl, CURLOPT_HEADER, true);
// 设置请求头
// 设置请求头
if (count($header) > 0) {
curl_setopt($cl, CURLO