zoukankan      html  css  js  c++  java
  • PHP中使用cURL实现Get和Post请求的方法

    1.通过get请求

     1 //使用curl实现get请求
     2 function curl_get($url){
     3     $ch = curl_init();
     4     curl_setopt($ch, CURLOPT_URL, $url);
     5     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     6     curl_setopt($ch, CURLOPT_HEADER, 0);
     7     $output = curl_exec($ch);
     8     curl_close($ch);
     9     return $output;
    10 }
    11                 

    2.通过post提交

     1 //使用curl实现Post请求
     2 function curl_post($url,$post_data){
     3     $ch = curl_init();
     4     curl_setopt($ch, CURLOPT_URL, $url);
     5     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     6     // post数据
     7     curl_setopt($ch, CURLOPT_POST, 1);
     8     // post的变量
     9     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    10     $output = curl_exec($ch);
    11     curl_close($ch);
    12     return $output;
    13 }
  • 相关阅读:
    栈的实现方式
    复合和继承
    循环链表和双向链表
    抽象类和接口
    private构造器和单例模式
    内部类
    关于初始化和清理
    多态的理解
    幾個小知識
    Youth
  • 原文地址:https://www.cnblogs.com/liruning/p/6080693.html
Copyright © 2011-2022 走看看