cURL模拟HTTP请求(支持HTTPS)
function setHttpRequest($url,$headers,$params=array(),$method="GET") {
$ci = curl_init();
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ci, CURLOPT_TIMEOUT, 30);
curl_setopt($ci, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ci, CURLOPT_URL, $url);
curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ci, CURLOPT_HEADER, FALSE);
curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
if($headers!=""){
curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
}else {
curl_setopt($ci, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
}
switch (strtoupper($method)){
case 'POST':
curl_setopt($ci, CURLOPT_POST, TRUE);
curl_setopt($ci, CURLOPT_POSTFIELDS, $params);
break;
case 'PUT':
curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ci, CURLOPT_POSTFIELDS, $params);
break;
case 'PATCH':
curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ci, CURLOPT_POSTFIELDS, $params);
break;
case 'DELETE':
curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ci, CURLOPT_POSTFIELDS, $params);
break;
default:
curl_setopt($ci, CURLOPT_HTTPGET, TRUE);
break;
}
$response = curl_exec($ci);
$httpCode = curl_getinfo($ci);
curl_close($ci);
return $response;
}
cURL模拟HTTP请求(支持HTTPS)的更多相关文章
- php curl模拟post请求提交数据样例总结
在php中要模拟post请求数据提交我们会使用到curl函数,以下我来给大家举几个curl模拟post请求提交数据样例有须要的朋友可參考參考.注意:curl函数在php中默认是不被支持的,假设须要使用 ...
- php curl模拟post请求的例子
curl 在php中要模拟post请求数据提交我们会使用到curl函数,下面我来给大家举几个curl模拟post请求提交数据例子有需要的朋友可参考参考. 注意:curl函数在php中默认是不被支持的, ...
- php curl模拟post请求提交数据例子总结
php curl模拟post请求提交数据例子总结 [导读] 在php中要模拟post请求数据提交我们会使用到curl函数,下面我来给大家举几个curl模拟post请求提交数据例子有需要的朋友可参考参考 ...
- php curl模拟post请求提交数据
最近在做校园图书馆图书信息的采集程序,既然是图书馆图书的采集,肯定有提交搜索的页面,无非是post提交,让我想到了curl模拟提交,首先通过firebug进行抓包查询下post提交后的格式如下: tx ...
- php使用curl模拟post请求
废话不多说,直接上代码,做个笔记. $url="http://localhost/header_server.php"; $body = array("mobile&qu ...
- curl模拟Http请求
一.get请求 curl "http://www.baidu.com" 如果这里的URL指向的是一个文件或者一幅图都可以直接下载到本地 curl -i "http://w ...
- curl 模拟ajax 请求
主要是在header请求里加一个 X-Requested-With: XMLHttpRequest curl -v -H "X-Requested-With: XMLHttpRequest ...
- curl模拟post请求
1,curl -d "userType=seller&userId=1034285" "www.baidu.com/getInfo.php" curl ...
- curl 模拟post请求
curl -H "Content-Type:application/json" -X POST --data '{"openId":"xxxxxxx& ...
随机推荐
- xtu read problem training 4 A - Moving Tables
Moving Tables Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ...
- KNN-K近邻算法(1)
KNN(K-nearest neighbors) 思想简单 数学所需知识少(近零) 效果好 可解释机器学习算法使用过程中的很多细节问题 更完整的刻画机器学习应用的流程 天然可解决多分类问题 可解决回归 ...
- [luoguP1944] 最长括号匹配_NOI导刊2009提高(1)
传送门 非常傻的DP. f[i]表示末尾是i的最长的字串 #include <cstdio> #include <cstring> #define N 1000001 int ...
- [luoguP2709] 小B的询问(莫队)
传送门 个数 1 2 3 4 5 答案 1 4 9 16 25 做差 1 3 5 7 9 显然增加一个数只需要增加 ton[a[x]] << 1 | 1 即可 减去一个数也减去这个 注意 ...
- Codeforces Round #259 (Div. 2) D
D. Little Pony and Harmony Chest time limit per test 4 seconds memory limit per test 256 megabytes i ...
- 跪啃SAM
struct SAM { ],size,last,pre[maxn],pos[maxn]; SAM() { size=; memset(ch[],,])); pre[]=-; } int idx(ch ...
- SharedPreferences保存用户偏好参数
package com.example.administrator.myapplication; import android.content.Context; import android.cont ...
- [bzoj3991][SDOI2015]寻宝游戏_树链的并_倍增lca_平衡树set
寻宝游戏 bzoj-3991 SDOI-2015 题目大意:题目链接. 注释:略. 想法:我们发现如果给定了一些点有宝物的话那么答案就是树链的并. 树链的并的求法就是把所有点按照$dfs$序排序然后相 ...
- POJ1328 Radar Installation 解题报告
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- Java电商项目-5.内容管理cms系统
目录 实现加载内容分类树功能 实现内容分类动态添加 删除内容分类节点 实现内容分类节点的分页显示 实现广告内容的添加 实现广告内容删除 实现广告内容编辑 到Github获取源码请点击此处 实现加载内容 ...