class Curl {
public static function content($url,$return=0){
//参数
$ch = curl_init();
//初始化//获取URL地址
curl_setopt($ch,CURLOPT_URL,$url);
//启用时会将头文件的信息作为数据流输出
curl_setopt($ch,CURLOPT_HEADER,0);
//不直接输出
curl_setopt($ch,CURLOPT_RETURNTRANSFER,$return);
//在HTTP请求中包含一个"User-Agent: "头的字符串
curl_setopt($ch,CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-type:text/xml'));
//设置 HTTP 头字段的数组
$str = curl_exec($ch);
if ($return) {
return $str;
}
}
public static function c_get($url,$data=array()){
//参数
// echo 1;die;
$ch = curl_init();
//初始化//获取URL地址
curl_setopt($ch,CURLOPT_URL,$url);
//启用时会将头文件的信息作为数据流输出
curl_setopt($ch,CURLOPT_HEADER,0);
//不直接输出
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
//在HTTP请求中包含一个"User-Agent: "头的字符串
curl_setopt($ch,CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-type:text/xml'));
//设置 HTTP 头字段的数组
return $str = curl_exec($ch);
}
public static function c_post($url,$data=''){
$curlobj = curl_init(); //初始化
//获取URL地址
if(0 === strpos(strtolower($url), 'https')) {
//tps请求
// echo 11;die;
curl_setopt($curlobj, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
// curl_setopt($curlobj, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在
}
curl_setopt($curlobj,CURLOPT_URL,$url);//启用时会将头文件的信息作为数据流输出
curl_setopt($curlobj,CURLOPT_HEADER,0);//不直接输出
curl_setopt($curlobj,CURLOPT_RETURNTRANSFER,1);//在HTTP请求中包含一个"User-Agent: "头的字符串
//print_r(curl_setopt());die;
curl_setopt($curlobj,CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);//指定POST方式传值
curl_setopt($curlobj,CURLOPT_POST,1);
curl_setopt($curlobj,CURLOPT_POSTFIELDS,$data);
//设置 HTTP 头字段的数组
curl_setopt($curlobj,CURLOPT_HTTPHEADER,array('application/x-www-form-urlencoded; charset=utf-8', 'Content-length:'.strlen($data)));
return $str = curl_exec($curlobj); //执行
}
}