/**
* @Description: curl请求
* @Author: Yang
* @param $url
* @param null $data
* @param string $method
* @param array $header
* @param bool $https
* @param int $timeout
* @return mixed
*/
function curl_request($url, $data=null, $method='get', $header = array("content-type: application/json"), $https=true, $timeout = 5){
$method = strtoupper($method);
$ch = curl_init();//初始化
curl_setopt($ch, CURLOPT_URL, $url);//访问的URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//只获取页面内容,但不输出
if($https){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//https请求 不验证证书
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//https请求 不验证HOST
}
if ($method != "GET") {
if($method == 'POST'){
curl_setopt($ch, CURLOPT_POST, true);//请求方式为post请求
}
if ($method == 'PUT' || strtoupper($method) == 'DELETE') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //设置请求方式
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//请求数据
}
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //模拟的header头
//curl_setopt($ch, CURLOPT_HEADER, false);//设置不需要头信息
$result = curl_exec($ch);//执行请求
curl_close($ch);//关闭curl,释放资源
return $result;
}

PHP 之CURL请求封装GET、POST、PUT、DELETE的更多相关文章

  1. curl请求的get.post.put.delete对接其他系统接口方法

    class HttpCurl{ //控客云平台的appid private $appId = xxxxxx; //控客云平台的appkey private $appKey = 'xxxxxxxxxxx ...

  2. php curl 请求封装

    /** * curl 封装函数 * @param string $url 请求地址 * @param string $data 请求数据 * @param string $type 请求方式 默认为G ...

  3. php CURL 发送请求封装

    cURL可以使用URL的语法模拟浏览器来传输数据,因为它是模拟浏览器,因此它同样支持多种协议,FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE 以及 ...

  4. PHP Request请求封装

    /** * Request请求封装 * Class Request * @package tool */ class Request { // curl 请求错误码 protected static ...

  5. curl操作封装

    <?php /** * Class Curl curl简单封装 get post */ class Curl { /** * @brief get请求 * @param $url 请求的url ...

  6. curl简单封装 get post

    Curl.php <?php /** * Class Curl curl简单封装 get post */ class Curl { /** * @brief get请求 * @param $ur ...

  7. Fiddler——如何抓取PHP的curl请求

    前言 本文主要介绍如何使用fiddler工具,来进行抓取PHP的curl请求,如果你会使用fiddler,那就是一行代码的事, 不会也没事,本文会教你如何简单的使用. 步骤 代码 设置桥接网络为127 ...

  8. 服务端CURL请求

    服务端与服务端之间,也存在接口编程. 比如我们网站服务端,需要发送短信.发送邮件.查询快递等,都需要调用第三方平台的接口. 1.php中发送请求 ①file_get_contents函数 :传递完整的 ...

  9. iOS开发——post异步网络请求封装

    IOS中有许多网络请求的函数,同步的,异步的,通过delegate异步回调的. 在做一个项目的时候,上网看了很多别人的例子,发现都没有一个简单的,方便的异步请求的封装例子.我这里要给出的封装代码,是异 ...

随机推荐

  1. Html5 history Api简介

    一. Html4的History API back() 后退,跟按下“后退”键是等效的. forward() 前进,跟按下“前进”键是等效的. go() 用法:history.go(x):在历史的范围 ...

  2. ci 在阿里云访问的时候404

    最近想把ci 弄到阿里云去,结果发现,本地好好的,到了阿里云就404了.网上查了下 原来是 配置文件的问题. 配置文件就是 vhost下面的 **.conf文件  要有这个才行 location / ...

  3. Linux下Shell编程

    Linux的shell编程 1.什么是shell? 当一个用户登录Linux系统之后,系统初始化程序init就为每个用户执行一个称为shell(外壳)的程序. shell就是一个命令行解释器,它为用户 ...

  4. 【Android自己定义View实战】之自己定义超简单SearchView搜索框

    [Android自己定义View实战]之自己定义超简单SearchView搜索框 这篇文章是对之前文章的翻新,至于为什么我要又一次改动这篇文章?原因例如以下 1.有人举报我抄袭,原文链接:http:/ ...

  5. ASP.NET Overview

    https://msdn.microsoft.com/en-us/library/4w3ex9c2.aspx ASP.NET is a unified统一的 Web development model ...

  6. windows下安装MySQL-python遇到的问题

    执行安装命令 pip install MySQL-python 一.执行时会报一个错误 error: Microsoft Visual C++ 9.0 is required (Unable to f ...

  7. poj2262 Goldbach's Conjecture——筛素数

    题目:http://poj.org/problem?id=2262 水水更健康~ 代码如下: #include<iostream> #include<cstdio> #incl ...

  8. Spark中统计程序运行时间

    import java.text.SimpleDateFormat import java.util.Date val s=NowDate() //显示当前的具体时间 val now=new Date ...

  9. 69.资金管理-税率表管理extjs 页面

    1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8&quo ...

  10. Ruby Range类

    创建: 2017/09/30