function getAction($url='')
{
// curl 请求一共分四步,初始化,设置属性,执行并获取结果,释放句柄
// 一、初始化
$curl = curl_init();

// 二、设置属性
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 跳过证书验证(https)的网站无法跳过,会报错
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书验证

curl_setopt($curl, CURLOPT_URL, $url); // 设置curl请求的地址
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 返回的数据不打印

// 三、发送请求,并接收数据
$data = curl_exec($curl);

// 四、释放句柄
curl_close($curl);
return $data; // 未对数据 json_decode()
}

// post请求
function postAction($url='', $data=array())
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}

curl 发送get post请求的更多相关文章

  1. php CURL 发送get,post请求

    // 发送一个get请求 $url 发送地址    function get($url)    {        //初始化操作        $curl = curl_init($url);     ...

  2. php 中使用cURL发送get/post请求,上传图片,批处理

    cURL是利用url语法规定传输文件和数据的工具.php中有curl拓展,一般用来实现网络抓取,模拟发送get   post请求,文件上传. 在php中建立curl的基本步骤如下: 1 初始化     ...

  3. php使用file_get_contents 或者curl 发送get/post 请求 的方法总结

    file_get_contents模拟GET/POST请求 模拟GET请求: <?php $data = array( 'name'=>'zhezhao', 'age'=>'23' ...

  4. php curl发送post get请求

    POST: function curl_post_https($url, $data, $header){ // 模拟提交数据函数 $curl = curl_init(); // 启动一个CURL会话 ...

  5. linux shell中curl 发送post请求json格式问题

    今天在linux中使用curl发送一个post请求时,带有json的数据,在发送时发现json中的变量没有解析出来 如下 curl -i -X POST -H 'Content-type':'appl ...

  6. 发送POST测试请求的若干方法

    最近在工作中需要测试发送带Json格式body值的HTTP POST请求.起初,我在Linux环境下使用curl命令去发送请求,但是,在发送的过程中却遇到了一些问题,经过一段时间的摸索,发现了以下几种 ...

  7. 转:PHP中的使用curl发送请求(GET请求和POST请求)

    原文地址:http://www.jb51.net/article/104974.htm 使用CURL发送请求的基本流程 使用CURL的PHP扩展完成一个HTTP请求的发送一般有以下几个步骤: 1.初始 ...

  8. curl 发送post请求

    curl 发送post请求 curl -X POST "http://localhost:8080/usr3?id=1&name=3&departmentId=2" ...

  9. curl 发送json请求

    curl 发送json请求 这个是在cmd环境下的输入:注意{\"userName\":\"helo\",\"id\":1}中间不能有空格 ...

随机推荐

  1. js 上传文件预览

    1. FILE API html5提供了FIle和FileReader两个方法,可以读取文件信息并读取文件. 2. example <html> <body> <div ...

  2. BZOJ 4326 树链剖分+二分+差分+记忆化

    去年NOIP的时候我还不会树链剖分! 还是被UOJ 的数据卡了一组. 差分的思想还是很神啊! #include <iostream> #include <cstring> #i ...

  3. 【LeetCode OJ】Convert Sorted Array to Binary Search Tree

    Problem Link: http://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ Same idea ...

  4. 第三个Sprint冲刺第一天

    讨论地点:宿舍 讨论成员:邵家文.李新.朱浩龙.陈俊金 讨论问题:再度强化四则运算app的功能.

  5. YUSE_DOWN-批下载

    *&---------------------------------------------------------------------**& Report YTST_CX_DO ...

  6. iTunesConnect进行App转移2-官方说明

    Can I transfer an app to another developer's iTunes Connect account? Yes, you can transfer your app ...

  7. viewpager接受值图片轮播

    package com.baway.test; import java.util.ArrayList;import java.util.List;import java.util.Timer;impo ...

  8. php:上传多个文件

    <?php class upload {    public $files;    public $seterror;    public $allowtype;    public $file ...

  9. 2016HUAS_ACM暑假集训1A - 士兵队列训练问题

    这道题我觉得是个简单的模拟题,整理一下思路,弄清楚题意就好了. 新手上路,采用两个数组进行交互赋值,用的方法也比较笨,思路差不多都在代码的注释里了. 下面是题目大意: 首先将士兵从1开始编号(士兵总数 ...

  10. WCF实现客户端自动更新

    IServiceUpdate using System.IO; using System.ServiceModel; using System.ServiceModel.Web; namespace ...