php curl get和post提交

  • 黄楚恒
  • 2017-11-01 09:53:42
  • PHP
  • php
// get方法请求
function getCurl($url) {//get https的内容
    $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);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

// post方法请求
function postCurl($url, $post) {//get https的内容
    $ch = curl_init(); //新建curl
    curl_setopt($ch, CURLOPT_URL, $url); //url  
    curl_setopt($ch, CURLOPT_POST, 1);  //post
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // ssl证书来源验证
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 检查ssl证书
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 作为一个流的形式返回还是直接输出
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); //post内容  
    $res = curl_exec($ch); //输出
    $arr = json_decode($res, true);
    curl_close($ch);
    return $arr;
}

Copyright © 2016-2019 709173702@qq.com 版权所有  ICP证粤ICP备16117826号-1
联系邮箱:709173702@qq.com