curl模板----php发送post,get请求
function _grab($curl,$ip='',$referer='',$postInfo='',$cookie=''){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $curl);
//不输出头
curl_setopt($ch, CURLOPT_HEADER, 0);
//以字符串返回获取的信息,不直接输出
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//SOCKS代理
if($ip){
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
$string_arr = explode(":", $ip);
curl_setopt($ch, CURLOPT_PROXY, $string_arr[0]);
curl_setopt($ch, CURLOPT_PROXYPORT, $string_arr[1]);
}
//如果是https链接,不验证证书
if(substr_count($curl,'https')){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
//POST
if($postInfo){
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postInfo);
}
//加入cookie
if($cookie){
curl_setopt($ch,CURLOPT_COOKIE,$cookie);
}
//模拟来路
if($referer){
curl_setopt($ch, CURLOPT_REFERER, $referer);
}
//模拟浏览器
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36');
//执行
$content = curl_exec($ch);
//错误处理
if ($content === false) {
return "网络请求出错: " . curl_error($ch);
exit();
}
return $content;
}
//php返回json
echo json_encode($data);
//php将返回的json转换成数组
json_decode($data,true);
//爬虫
function _grab($curl,$postInfo='',$cookie='',$referer=''){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $curl);
//不输出头
curl_setopt($ch, CURLOPT_HEADER, 0);
//以字符串返回获取的信息,不直接输出
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果是https链接,不验证证书
if(substr_count($curl,'https')){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
//POST
if($postInfo){
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postInfo);
}
//加入cookie
if($cookie){
curl_setopt($ch,CURLOPT_COOKIE,$cookie);
}
//模拟来路
if($referer){
curl_setopt($ch, CURLOPT_REFERER, $referer);
} //模拟浏览器
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'); //执行
$content = curl_exec($ch);
//错误处理
if ($content === false) {
return "网络请求出错: " . curl_error($ch);
exit();
}
return $content;
}
curl模板----php发送post,get请求的更多相关文章
- php使用curl模拟多线程发送请求
每个PHP文件的执行是单线程的,但是php本身也可以用一些别的技术实现多线程并发比如用php-fpm进程,这里用curl模拟多线程发送请求.php的curl多线程是通过不断调用curl_multi_e ...
- php CURL 发送get,post请求
// 发送一个get请求 $url 发送地址 function get($url) { //初始化操作 $curl = curl_init($url); ...
- php 中使用cURL发送get/post请求,上传图片,批处理
cURL是利用url语法规定传输文件和数据的工具.php中有curl拓展,一般用来实现网络抓取,模拟发送get post请求,文件上传. 在php中建立curl的基本步骤如下: 1 初始化 ...
- php curl发送post get请求
POST: function curl_post_https($url, $data, $header){ // 模拟提交数据函数 $curl = curl_init(); // 启动一个CURL会话 ...
- PHP实现微信模板消息发送给指定用户
使用公众号的模板消息功能,必须是认证过的服务号,需要发送微信号的openid,同一微信号在不同公众号下的openid是不同的,在公众号下是唯一的,获取不到微信号 进入公众平台 功能->模板消息 ...
- 发送POST测试请求的若干方法
最近在工作中需要测试发送带Json格式body值的HTTP POST请求.起初,我在Linux环境下使用curl命令去发送请求,但是,在发送的过程中却遇到了一些问题,经过一段时间的摸索,发现了以下几种 ...
- 使用CURL实现GET和POST方式请求
/** 使用curl方式实现get或post请求@param $url 请求的url地址@param $data 发送的post数据 如果为空则为get方式请求return 请求后获取到的数据 */f ...
- php使用CURL实现GET和POST方式请求
CURL请求,支持GET和POST两种方式,默认为GET方式,如果传第二个参数则为POST方式请求,设置了超时时间,避免程序卡死. /** 使用curl方式实现get或post请求 @param $u ...
- 如果调用ASP.NET Web API不能发送PUT/DELETE请求怎么办?
理想的RESTful Web API采用面向资源的架构,并使用请求的HTTP方法表示针对目标资源的操作类型.但是理想和现实是有距离的,虽然HTTP协议提供了一系列原生的HTTP方法,但是在具体的网络环 ...
随机推荐
- python3练习100题——054
题目:取一个整数a从右端开始的4〜7位. a=input('please input a num:') print(a[-7:-3])
- GYCTF easy_thinking
前期储备:ThinkPHP6 任意文件操作漏洞分析 https://paper.seebug.org/1114/ 学习链接: https://www.freebuf.com/articles/web/ ...
- jQuery---城市选择案例
城市选择案例 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UT ...
- 在ASP.NET 中调用 WebService 服务
一.webservice定义 详见 https://www.cnblogs.com/phoebes/p/8029464.html 二.在ASP.NET MVC 中调用 webservice 1:要调用 ...
- PP: Learning representations for time series clustering
Problem: time series clustering TSC - unsupervised learning/ category information is not available. ...
- Qt VS Tools插件官方下载及安装
下载 官方下载地址:https://download.qt.io/development_releases/vsaddin/(国外网站直接打开超级慢) 找到对应的VS版本下载 安装 下载完成后安装,打 ...
- 自己动手系列----使用数组实现一个简单的Set
Set:注重独一无二的性质,该体系集合可以知道某物是否已近存在于集合中,不会存储重复的元素用于存储无序(存入和取出的顺序不一定相同)元素,值不能重复.主要有HashSet和TreeSet两大实现类. ...
- 原来window 也可以使用pthreads
https://blog.csdn.net/clever101/article/details/101029850
- [CCPC2019秦皇岛] F. Forest Program
[CCPC2019秦皇岛 F] Link https://codeforces.com/gym/102361/problem/F Description 给定一个仙人掌,删去一些边可以让它变成一个森林 ...
- An easy problem(位运算)
As we known, data stored in the computers is in binary form.(数据以二进制形式存储于电脑之中.)The problem we discuss ...