//通过curl模拟post的请求;
function SendDataByCurl($url,$data=array()){
//对空格进行转义
$url = str_replace(' ','+',$url);
$ch = curl_init();
//设置选项,包括URL
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_TIMEOUT,3); //定义超时3秒钟
// POST数据
curl_setopt($ch, CURLOPT_POST, 1);
// 把post的变量加上
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); //<span style="color: #ff0000;"><strong>所需传的数组用http_bulid_query()函数处理一下,就ok了-发送多维数组</strong></span>
//执行并获取url地址的内容
$output = curl_exec($ch);
$errorCode = curl_errno($ch);
//释放curl句柄
curl_close($ch);
if(0 !== $errorCode) {
return false;
}
return $output;
}
curl发送多维数组
版权归原作者所有,如有侵权请告知。达维营-前端网 » curl发送多维数组
相关推荐
- PHP将时间戳格式化为几分钟前、几小时前、几天前
- Flashfxp文件传输到服务器后部分文件代码报错
- php7.4报错:Trying to access array offset on value of type null
- Thinkphp切换php版本报错:implode(): Passing glue string after array is deprecated. Swap the parameters
- php报错:Parse error: syntax error, unexpected end of file;Parse error: syntax error, unexpected end of file “]”
- getimagesize(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed - php end,array_shift,array_pop Only variables can be passed by reference
- laravel常用插件库