public function my_curl($url,$token,$data=''){
$headers = [];
if (isset($token)) {
$headers = [
'Content-Type:application/json;charset=UTF-8',
"Authorization: Bearer {$token}"
];
}
$ch = curl_init();
curl_setopt( $ch , CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
if ($data!='') {
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
}
$res = curl_exec( $ch );
curl_close( $ch );
return $res;
}
带bear的http请求
最新推荐文章于 2024-06-11 11:51:56 发布