1.通过get请求
1 //使用curl实现get请求 2 function curl_get($url){ 3 $ch = curl_init(); 4 curl_setopt($ch, CURLOPT_URL, $url); 5 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 6 curl_setopt($ch, CURLOPT_HEADER, 0); 7 $output = curl_exec($ch); 8 curl_close($ch); 9 return $output; 10 } 11
2.通过post提交
1 //使用curl实现Post请求 2 function curl_post($url,$post_data){ 3 $ch = curl_init(); 4 curl_setopt($ch, CURLOPT_URL, $url); 5 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 6 // post数据 7 curl_setopt($ch, CURLOPT_POST, 1); 8 // post的变量 9 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 10 $output = curl_exec($ch); 11 curl_close($ch); 12 return $output; 13 }