/**
- curl远程传输工具
*/
public function postCurl_new($url,$body,$header,$type='POST'){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);//0只要正文,1全部信息
curl_setopt($ch,CURLOPT_TIMEOUT,5);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
// array_push($header,'Accept:application/json');
// array_push($header,'Content-Type:application/json');
// array_push($header,'http:multipart/form-data');
if(count($body)>0){
curl_setopt($ch,CURLOPT_POSTFIELDS,$body);
}
if(count($header)>0){
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
}
//设置上传文件相关
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_MAXREDIRS,3);//递归
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
switch ($type) {
case 'GET':
curl_setopt($ch,CURLOPT_HTTPGET,1);
break;
case 'POST':
curl_setopt($ch,CURLOPT_POST,1);
break;
case 'PUT':
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,'PUT');
break;
case 'DELETE':
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,'DELETE');
break;
}
curl_setopt($ch,CURLOPT_ENCODING,'gzip');
curl_setopt($ch,CURLOPT_USERAGENT,'SSTS Browser/1.0');
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)');
if(curl_errno($ch)){
return curl_error($ch);
}
$content = curl_exec($ch);
curl_close($ch);
$result = json_decode($content,true);
if(!empty($result)){
return $result;
}else{
return $content;
}
}
点击查看更多内容
3人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦