php发送post请求

Ezra
2021-04-02 / 0 评论 / 194 阅读 / 正在检测是否收录...
public function curl_post($url , $data=array()){

  $ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, $url);

  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

  // POST数据

  curl_setopt($ch, CURLOPT_POST, 1);

  // 把post的变量加上
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data,JSON_UNESCAPED_UNICODE));

  $output = curl_exec($ch);

  curl_close($ch);

  return $output;

  }
0

评论 (0)

取消