function curl_request($API,$method = ‘GET‘,$params = array(),$headers = [],$Json_decode = true)
{
$curl = curl_init();
switch (strtoupper($method)) {
case ‘GET‘:
if (!empty($params)) {
$API .= (strpos($API,‘?‘) ? ‘&‘ : ‘?‘) . http_build_query($params);
}
curl_setopt($curl,CURLOPT_httpGET,true);
break;
case ‘POST‘:
curl_setopt($curl,CURLOPT_POST,true);
if(is_array($params)) {
$params = http_build_query($params);
}
curl_setopt($curl,CURLOPT_POSTFIELDS,$params);
break;
case ‘PUT‘:
curl_setopt($curl,CURLOPT_CUSTomrEQUEST,‘PUT‘);
curl_setopt($curl,$params);
break;
case ‘DELETE‘:
curl_setopt($curl,‘DELETE‘);
curl_setopt($curl,$params);
break;
}
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,CURLOPT_URL,$API);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_MAXREDirs,10);
curl_setopt($curl,CURLOPT_TIMEOUT,30);
curl_setopt($curl,CURLOPT_header,0);
curl_setopt($curl,CURLOPT_httpheader,$headers);
if(isset($_SERVER[‘http_USER_AGENT‘])){
curl_setopt($curl,CURLOPT_USERAGENT,$_SERVER[‘http_USER_AGENT‘]);
}
总结 以上是内存溢出为你收集整理的CURL请求处理全部内容,希望文章能够帮你解决CURL请求处理所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)