function SendDataByCurl($url,$data=array()){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_TIMEOUT,3);
// POST数据
curl_setopt($ch, CURLOPT_POST, 1);
// 把post的变量加上
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); //!!!!!!!!!!!!!!
//执行并获取url地址的内容
$output = curl_exec($ch);
$errorCode = curl_errno($ch);
//释放curl句柄
curl_close($ch);
if(0 !== $errorCode) {
return false;
}
return $output;
}
php curl post 多维数组
最新推荐文章于 2024-01-11 09:58:50 发布
本文介绍了一个PHP函数,用于通过Curl发送POST请求。该函数初始化Curl会话,设置URL、返回值类型、超时时间等参数,并将POST数据附加到请求中。最后,执行Curl请求并返回响应数据。
712

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



