惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
C
Check Point Blog
I
InfoQ
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
月光博客
月光博客
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
Y
Y Combinator Blog
博客园 - Franky
博客园_首页
罗磊的独立博客
量子位
美团技术团队
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Martin Fowler
Martin Fowler
博客园 - 叶小钗
aimingoo的专栏
aimingoo的专栏

博客园 - 小馬過河﹎

一些有用的javascript函数 layui多文件上传表格 layui静态表格防止被内容撑开变形 php使用mysql-text字段存取json字符串 ThinkPHP3 系统常量__SELF__在生产模式(debug=false)下不更新 PHP将数据表里的两个字段映射成对象的键和值 普通表格table样式美化 查看证书/apk指纹md5/sha1/sha256 php跨域 javascript使用正则表达式高亮关键字 博文阅读密码验证 - 博客园 [转载]php递归生成树形结构(几种常见的数据结构) PHP二维数组排序|PHP二维数组去重 textarea中禁止使用换行(回车) php json_encode 斜杠 反斜杠 转义处理 ThinkPHP获取当前url js获取url中的查询参数 layui多图片上传 ThinkPHP接收header自定义参数
PHP通用请求函数sendCurl
小馬過河﹎ · 2023-08-19 · via 博客园 - 小馬過河﹎
function sendCurl($url, $data = null, $method = 'POST') {
	$method = strtoupper($method);
	$start_wdmcurl_time = microtime(true);

	$header = array(' application/x-www-form-urlencoded');
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_FAILONERROR, false);
	// https 请求
	if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
	}
	if ($method == 'GET') {
		if ($data && is_array($data) && count($data) > 0) {
			$url .= "?" . http_build_query($data);
		}
		curl_setopt($ch, CURLOPT_URL, $url);
	} elseif ($method == 'POST') {
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		if (is_array($data) && count($data) > 0) {
			curl_setopt($ch, CURLOPT_POST, true);
			$isPostMultipart = false;
			foreach ($data as $k => $v) {
				if ('@' == substr($v, 0, 1)) {
					$isPostMultipart = true;
					break;
				}
			}
			unset($k, $v);
			if ($isPostMultipart) {
				curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
			} else {
				curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
			}
		}
	} elseif (in_array($method, ['PUT', 'DELETE', 'PATCH'])) {
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	}
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
	$reponse = curl_exec($ch);
	curl_close($ch);
	return $reponse;
}