//通过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));  //所需传的数组用http_bulid_query()函数处理一下,就ok了-发送多维数组
  //执行并获取url地址的内容
  $output = curl_exec($ch);
  $errorCode = curl_errno($ch);
  //释放curl句柄
  curl_close($ch);
  if(0 !== $errorCode) {
    return false;
  }
  return $output;
}

相关文章:

  • 2021-08-05
  • 2021-08-05
  • 2021-07-16
  • 2021-08-09
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
猜你喜欢
  • 2022-12-23
  • 2021-05-22
  • 2022-01-04
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2022-01-18
相关资源
相似解决方案