PHP 之CURL请求封装GET、POST、PUT、DELETE
/**
* @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的更多相关文章
- curl请求的get.post.put.delete对接其他系统接口方法
class HttpCurl{ //控客云平台的appid private $appId = xxxxxx; //控客云平台的appkey private $appKey = 'xxxxxxxxxxx ...
- php curl 请求封装
/** * curl 封装函数 * @param string $url 请求地址 * @param string $data 请求数据 * @param string $type 请求方式 默认为G ...
- php CURL 发送请求封装
cURL可以使用URL的语法模拟浏览器来传输数据,因为它是模拟浏览器,因此它同样支持多种协议,FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE 以及 ...
- PHP Request请求封装
/** * Request请求封装 * Class Request * @package tool */ class Request { // curl 请求错误码 protected static ...
- curl操作封装
<?php /** * Class Curl curl简单封装 get post */ class Curl { /** * @brief get请求 * @param $url 请求的url ...
- curl简单封装 get post
Curl.php <?php /** * Class Curl curl简单封装 get post */ class Curl { /** * @brief get请求 * @param $ur ...
- Fiddler——如何抓取PHP的curl请求
前言 本文主要介绍如何使用fiddler工具,来进行抓取PHP的curl请求,如果你会使用fiddler,那就是一行代码的事, 不会也没事,本文会教你如何简单的使用. 步骤 代码 设置桥接网络为127 ...
- 服务端CURL请求
服务端与服务端之间,也存在接口编程. 比如我们网站服务端,需要发送短信.发送邮件.查询快递等,都需要调用第三方平台的接口. 1.php中发送请求 ①file_get_contents函数 :传递完整的 ...
- iOS开发——post异步网络请求封装
IOS中有许多网络请求的函数,同步的,异步的,通过delegate异步回调的. 在做一个项目的时候,上网看了很多别人的例子,发现都没有一个简单的,方便的异步请求的封装例子.我这里要给出的封装代码,是异 ...
随机推荐
- docker run和nsenter
docker run和nsenter 1,本机运行java -version没有内容, 使用 docker run java java -version就有内容了: 2, docker run -d ...
- Pixhawk---超声波模块加入说明(I2C方式)
1 说明 在Pixhawk的固件中,已经实现了串口和i2c的底层驱动,并不须要自己去写驱动.通过串口的方式加入超声波的缺点是串口不够.不能加入多个超声波模块,此时须要用到i2c的方式去加入了.在P ...
- Mysql net start mysql启动,提示发生系统错误 5 拒绝訪问 解决之道
当前用户的操作权限太低了,出了问题 出错问题截屏例如以下: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/4 ...
- CF 445B(DZY Loves Chemistry-求连通块)
B. DZY Loves Chemistry time limit per test 1 second memory limit per test 256 megabytes input standa ...
- React Native 中的component 的生命周期
React Native中的component跟Android中的activity,fragment等一样,存在生命周期,下面先给出component的生命周期图 getDefaultProps ob ...
- #HDU 3790 最短路径问题 【Dijkstra入门题】
题目: 最短路径问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- Codeforces Round #263 (Div. 1)-A,B,C
A: 这道题目还是非常easy的,做过非常多遍了.相似于分割木板的问题. 把全部的数放在一个优先队列里,弹出两个最大的,然后合并,把结果放进去.依次进行. #include <iostream& ...
- 删除windows服务 cygwin sshd
$ cygrunsrv -R sshd 删除ssd服务
- LeetCode 819. Most Common Word (最常见的单词)
Given a paragraph and a list of banned words, return the most frequent word that is not in the list ...
- 一分钟让你了解Microsoft Edge
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...