// 发送一个get请求 $url 发送地址
    function get($url)
    {
        //初始化操作
        $curl = curl_init($url);
        //设置请求参数
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//设置结果的转换
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);//设置超时时间
        // 发送请求
        $res = curl_exec($curl);
        return $res;
    }
    /*
       $url 请求的接口地址  
       $data 上传资源的地址    
    */
    function post($url, $data)
    {
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        //发送
        $res = curl_exec($curl);
        return $res;
    }

相关文章:

  • 2022-12-23
  • 2021-09-12
  • 2022-02-27
  • 2021-06-21
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-01
  • 2022-12-23
  • 2021-11-13
  • 2022-12-23
  • 2021-10-17
  • 2021-10-08
  • 2022-12-23
相关资源
相似解决方案