<?php
function post($url, $data)
{
//初使化init方法
$ch = curl_init();
//指定URL
curl_setopt($ch, CURLOPT_URL, $url);
//设定请求后返回结果
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//声明使用POST方式来进行发送
curl_setopt($ch, CURLOPT_POST, 1);
//发送什么数据呢
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//忽略证书
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//忽略header头信息
curl_setopt($ch, CURLOPT_HEADER, 0);//1输出头信息
//设置超时时间
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
//curl_setopt($ch, CURLOPT_REFERER, $refer); //来路模拟
//curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file); //存储提交后得到的cookie数据
//curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file); //使用提交后得到的cookie数据做参数
//curl_setopt($ch, CURLOPT_PROXY, $ip);
//curl_setopt($ch, CURLOPT_PROXYPORT, $port);
//curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
//发送请求
$output = curl_exec($ch);
if(curl_errno($ch)){
exit(curl_error($ch));
}
//关闭curl
curl_close($ch);
//返回数据
return $output;
}
function get($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$text = curl_exec($ch);
if(curl_errno($ch)){
exit(curl_error($ch));
}
curl_close($ch);
return $text;
}
?>
Last modification:April 14th, 2020 at 10:12 am
© 允许规范转载