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 }
  • 相关阅读:
    第 2 章 MySQL 架构组成
    MySql学习笔记
    大型项目成功的关键
    内连接区别外连接
    UML2.0
    软件架构师之路
    UVA
    ZOJ
    UVA
    UVA
  • 原文地址:https://www.cnblogs.com/liruning/p/6080693.html
Copyright © 2011-2022 走看看