/**
- 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;
}
}
點(diǎn)擊查看更多內(nèi)容
3人點(diǎn)贊
評(píng)論
評(píng)論
共同學(xué)習(xí),寫(xiě)下你的評(píng)論
評(píng)論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得
100積分直接送
付費(fèi)專(zhuān)欄免費(fèi)學(xué)
大額優(yōu)惠券免費(fèi)領(lǐng)